alert('SceneScene1.js loaded');

function SceneScene1() {

};

SceneScene1.prototype.initialize = function () {
	alert("SceneScene1.initialize()");
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here
	// scene HTML and CSS will be loaded before this function is called

};

SceneScene1.prototype.handleShow = function (data) {
	alert("SceneScene1.handleShow()");
	// this function will be called when the scene manager show this scene
};

SceneScene1.prototype.handleHide = function () {
	alert("SceneScene1.handleHide()");
	// this function will be called when the scene manager hide this scene
};

SceneScene1.prototype.handleFocus = function () {
	alert("SceneScene1.handleFocus()");
	// this function will be called when the scene manager focus this scene
};

SceneScene1.prototype.handleBlur = function () {
	alert("SceneScene1.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
};

select = 0;

SceneScene1.prototype.handleKeyDown = function (keyCode) {
	alert("SceneScene1.handleKeyDown(" + keyCode + ")");
	
	alert("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
	// TODO : write an key event handler when this scene get focued
	switch (keyCode) {
		case sf.key.LEFT:
			if(select > 0)
				select -= 1;
			selectElement(select);
			break;
		case sf.key.RIGHT:
			if(select == 3){
				select += 1;
				selectElement(select);
				select = 0;
			}else{
				select += 1;
				selectElement(select);
			}
			break;
		case sf.key.UP:
			if(select == 3){
				select += 1;
				selectElement(select);
				select = 0;
			}else{
				select += 1;
				selectElement(select);
			}
			break;
		case sf.key.DOWN:
			if(select > 0)
				select -= 1;
			selectElement(select);
			break;
		case sf.key.ENTER:
			break;
		default:
			alert("handle default key event, key code(" + keyCode + ")");
			break;
	}
};

selectElement = function (element){
	
	switch (element) {
		case 0:
			document.getElementById('ielements').contentWindow.document.getElementById('histograma').checked = 0;
			document.getElementById('ielements').contentWindow.gestionarHistograma();
			
			document.getElementById('ielements').contentWindow.document.getElementById('piechart').checked = 0;
			document.getElementById('ielements').contentWindow.gestionarPiechart();
			break;
		case 1:
			document.getElementById('ielements').contentWindow.document.getElementById('histograma').checked = 1;
			document.getElementById('ielements').contentWindow.gestionarHistograma();
			break;
		case 2:
			document.getElementById('ielements').contentWindow.document.getElementById('piechart').checked = 1;
			document.getElementById('ielements').contentWindow.gestionarPiechart();
			break;
		case 3:
		
			break;
		case 4:
		
			break;
		case 5:
		
			break;
		default:
		
			break;
	}
};
