var widgetAPI = new Common.API.Widget();
var tvKey = new Common.API.TVKeyValue();

var Main = {

};

Main.onLoad = function() {
	// Enable key event processing
	this.enableKeys();
	widgetAPI.sendReadyEvent();
	mySound = document.getElementById("audio1");
	mySound.setAttribute("src", "Card.mp3");
	mySound.play();
	setInterval(function() {
		mySound.play();
	}, "1000");

	$(function() {
		$("#slides").slidesjs({
			navigation : {
				active : true,
				width : 200,
				height : 200,
				effect : "slide"
			}
		});
	});
	var stopInterval = false;
	var myVar = setInterval(function() {
		if ($('.slidesjs-next').css('display') == "block") {
			$(".slidesjs-next").css('display', "none");
			$(".slidesjs-previous").css('display', "none");
			stopInterval = true;
		}
	}, 1);
	if (stopInterval == true)
		clearInterval(myVar);
};

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);
		parent.location = "Menu.html";
		break;
	case tvKey.KEY_LEFT:
		alert("LEFT");
		$(".slidesjs-previous ").click();
		break;
	case tvKey.KEY_RIGHT:
		alert("RIGHT");
		$(".slidesjs-next").click();
		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");
		break;
	case tvKey.KEY_PAUSE:
		alert("PAUSE");
		var myVideo = document.getElementById("audio1");
		myVideo.pause();
	case tvKey.KEY_STOP:
		alert("PAUSE");
		var myVideo = document.getElementById("audio1");
		myVideo.stop();
		break;
	case tvKey.KEY_PLAY:
		alert("PLAY");
		// Sound Play
		mySound = document.getElementById("audio1");
		mySound.setAttribute("src", "Card.mp3");
		mySound.play();
		setInterval(function() {
			mySound.play();
		}, "1000");
		// End Sound
		break;
	default:
		alert("Unhandled key");
		break;
	}
};