var widgetAPI = new Common.API.Widget();
var tvKey = new Common.API.TVKeyValue();
var avatar = 1;
var Main = {

};

Main.onLoad = function() {
	// Enable key event processing
	this.enableKeys();
	widgetAPI.sendReadyEvent();
	avatar = sessionStorage.getItem("avatar");
	document.getElementById('BoxAvatarPlayer').innerHTML += '<img class="AvatarPlayer" src="app/images/Avatar/Avatar'
			+ avatar + '.png" />';
	g = new SingleGame();
	g.Game();
};

Main.onUnload = function() {

};

Main.enableKeys = function() {
	document.getElementById("anchor").focus();
};

Main.keyDown = function() {
	var keyCode = event.keyCode;
	alert("Key pressed: " + keyCode);

	switch (keyCode) {
	case tvKey.KEY_RETURN:
	case tvKey.KEY_PANEL_RETURN:
		alert("RETURN");
		// widgetAPI.sendReturnEvent();
		widgetAPI.blockNavigation(event);
		if (document.getElementById("popupReturn").style.display=="none")
		document.getElementById("popupReturn").style.display = "block";
		else
			{
				document.getElementById("popupReturn").style.display = "none";
			}
		
	//parent.location = "Menu.html";
		
		break;
	case tvKey.KEY_RED:
		alert("PASSER");
		g.pass();
		
		break;
	case tvKey.KEY_GREEN:
		alert("PULL");
		g.pull();
		

		break;
	case tvKey.KEY_EXIT:
		alert("Exit");
		if (document.getElementById("popupReturn").style.display=="none")
			document.getElementById("popupReturn").style.display = "block";
			else
				{
				parent.location = "Menu.html";
				}
		

		break;	
	case tvKey.KEY_LEFT:
		alert("LEFT");
		break;
	case tvKey.KEY_RIGHT:
		alert("RIGHT");
		break;
	case tvKey.KEY_UP:
		alert("UP");

		break;
	case tvKey.KEY_DOWN:
		alert("DOWN");

		break;
	case tvKey.KEY_ENTER:
	case tvKey.KEY_PANEL_ENTER:
		alert("ENTER");
		if (g.RoundFinish == true )
		{
			g.Inisialisation();
		}
		break;
	default:
		alert("Unhandled key");
		break;
	}
};
