/**
 * Processing.js instance and contants.
 */
var PJS = undefined;
var PC = undefined;

var Container = undefined;
var Canvas = undefined;

var PrototypesList = [];

var DRAW_CONTEXT = undefined;

var i = 0;
var j = 0;

var Lab = function() {
	var that = this,
		initilized = false,
		// freeze the change when something happen: 
		// window resize, game asked for stop...
		isPaused = false;

//------------------------------------------------------------------------------
// Private methods

	/**
	 * Setup the sketch.
	 */
	function pjsSetup() {
		PJS.size( Canvas.width , Canvas.height );
		PJS.background(255);
		PJS.smooth();
	};
	
	/**
	 * Responsible to draw.
	 */
	function pjsDraw() {

		DRAW_CONTEXT();

	};

	/**
	 * Set a new size for the processing instance.
	 * @return {void}
	 */
	function resizedStage() {
		PJS.size( Canvas.width, Canvas.height );
	};

	/**
	 * Pause the processing instance.
	 * @return {void}
	 */
	function pauseProcessing() {
		if (!isPaused){
			isPaused = true;
			PJS.noLoop();
		}
	};

	/**
	 * Resume the processing instance.
	 * @return {void}
	 */
	function resumeProcessing() {
		if (isPaused){
			isPaused = false;
			PJS.loop();
		}
	};

//
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// DOM Stuff
	

	/**
	 * When the page (document) lose the focus, we has to stop the processing loop.
	 * @return {void}		 
	 */
	function onBlur(event) {
		pauseProcessing();
	};

	/**
	 * When the page (document) get the focus back, we should ask for the 
	 * user when he wants to resume the game.
	 * @return {void}
	 */
	function onFocus(event) {
		resumeProcessing();
	};

	/**
	 * When the window is resized, stop processing, resize the sketch and resume the 
	 * game.
	 * @return {void}
	 */
	function onResize(event) {
		pauseProcessing();
		resizedStage();
		resumeProcessing();
	};

//
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Methods

	this.changePrototype = function( event ) {
		var target = event.target;
		var pid = target.getAttribute("data-prototype-id");

		switch(parseInt(pid)) {
			case 4:
				console.log("Case 4;");
				DRAW_CONTEXT = new P4(PJS,PC);
			break;
			case 3:
				console.log("Case 3;");
				DRAW_CONTEXT = new P3(PJS,PC);
			break;
			case 2:
				console.log("Case 2;");
				DRAW_CONTEXT = new P2(PJS,PC);
			break;
			case 1:
			default:
				console.log("Case 1;");
				DRAW_CONTEXT = new P1(PJS,PC);
			break;
		}

	};

//
//------------------------------------------------------------------------------

};

window.Lab = new Lab;


var Buttons = function () {
	
	
	
};
