
var view = "Main";
var iconSelected = 0;

var screenShots = 0;
var screenShotOnScreen = 0;

var alerts = 0;

window.onresize = setPosition;

//var clock = new Image();
//clock.src = "./image/clock.png";
//lock.href = "http://www.ovi.com"

function init(){
    
	//alert("Jep");
	
	initMainView();
    
    setPosition();
	
}

function initDocumentImage(docImage, image){

	docImage.src = image.src;
	//docImage.href = image.href;
	//docImage.height = image.height;
	//docImage.width = image.width;
	
}

function naviPush(){

	if (alerts == 1) { alert("Navi push"); }
	
	if (view == "Main") { view = "Apps"; }
	else if (view == "Apps") { view = "Main"; }
	else if (view == "screenShots") { view = "Main"; }
	
	if (view == "Apps") { initAppsView(); }
	else if (view == "Main") { initMainView(); }
	
	
}

function redPhonePush(){

	if (alerts == 1) { alert("Red phone"); }
	
	if (view != "screenShots") { return; }
	
	if (view == "screenShots") { view = "Apps"; }
	//else if (view == "Apps") { view = "Main"; }
	
	if (view == "Apps") { initAppsView(); }
	//else if (view == "Main") { initMainView(); }
}

function initMainView() {

	var f = document.getElementById( 'controls' );
	f.style.display = 'block'; // "none" = hide form
	
	var c = document.getElementById( 'screenshots' );
	c.style.display = 'none'; // "block" = show form

	var n97 = new Image();
	n97.src = "./image/n97.jpg";
	
	var navi = new Image();
	navi.src = "./image/navi.png";
	
	var redPhone = new Image();
	redPhone.src = "./image/redPhoneButton.png"
	
	var icon1 = new Image();
	icon1.src = "./image/icon1/icon1Front.png";
	
	var icon2 = new Image();
	icon2.src = "./image/icon2/icon2Front.png";
	
	var icon3 = new Image();
	icon3.src = "./image/icon3/icon3Front.png";
	
	var icon4 = new Image();
	icon4.src = "./image/icon4/icon4Front.png";
	
	var icon5 = new Image();
	icon5.src = "./image/icon5/icon5Front.png";
	
	var icon6 = new Image();
	icon6.src = "./image/icon6/icon6Front.png";
	
	var icon7 = new Image();
	icon7.src = "./image/icon7/icon7Front.png";
	
	var icon8 = new Image();
	icon8.src = "./image/icon8/icon8Front.png";
	
	var icon9 = new Image();
	icon9.src = "./image/icon9/icon9Front.png";
	
	var screenshot = new Image();
	screenshot.scr = "./image/scrshot1.png";
	
	
	if (document.images)
	{
    initDocumentImage(document.images.phone, n97);
	initDocumentImage(document.images.phone1, n97);
	
	initDocumentImage(document.images.naviButton, navi);
	initDocumentImage(document.images.naviButton1, navi);
	
	initDocumentImage(document.images.redPhoneButton, redPhone);
	initDocumentImage(document.images.redPhoneButton1, redPhone);
	
	initDocumentImage(document.images.icon1, icon1);
	initDocumentImage(document.images.icon2, icon2);
	initDocumentImage(document.images.icon3, icon3);
	initDocumentImage(document.images.icon4, icon4);
	initDocumentImage(document.images.icon5, icon5);
	initDocumentImage(document.images.icon6, icon6);
	initDocumentImage(document.images.icon7, icon7);
	initDocumentImage(document.images.icon8, icon8);
	initDocumentImage(document.images.icon9, icon9);
	initDocumentImage(document.images.screenshot, screenshot);
	}
	
	var f = document.getElementById( 'text' );
	f.textfield.value = "Click the menu button of the Nokia N97 to go to Hyperkani Symbian games listing."; // "none" = hide form
}


function initAppsView(){

	var f = document.getElementById( 'controls' );
	f.style.display = 'block'; // "none" = hide form
	
	var c = document.getElementById( 'screenshots' );
	c.style.display = 'none'; // "block" = show form
	

	var apps = new Image();
	apps.src = "./image/n97applications.png";
	
	var icon1 = new Image();
	icon1.src = "./image/icon1/icon1App.png";
	
	var icon2 = new Image();
	icon2.src = "./image/icon2/icon2App.png";
	
	var icon3 = new Image();
	icon3.src = "./image/icon3/icon3App.png";
	
	var icon4 = new Image();
	icon4.src = "./image/icon4/icon4App.png";
	
	var icon5 = new Image();
	icon5.src = "./image/icon5/icon5App.png";
	
	var icon6 = new Image();
	icon6.src = "./image/icon6/icon6App.png";
	
	var icon7 = new Image();
	icon7.src = "./image/icon7/icon7App.png";
	
	var icon8 = new Image();
	icon8.src = "./image/icon8/icon8App.png";
	
	var icon9 = new Image();
	icon9.src = "./image/icon9/icon9App.png";
	
	if (document.images)
	{
    initDocumentImage(document.images.phone, apps);
	initDocumentImage(document.images.icon1, icon1);
	initDocumentImage(document.images.icon2, icon2);
	initDocumentImage(document.images.icon3, icon3);
	initDocumentImage(document.images.icon4, icon4);
	initDocumentImage(document.images.icon5, icon5);
	initDocumentImage(document.images.icon6, icon6);
	initDocumentImage(document.images.icon7, icon7);
	initDocumentImage(document.images.icon8, icon8);
	initDocumentImage(document.images.icon9, icon9);
	}
	
	var f = document.getElementById( 'text' );
	f.textfield.value = "Click the game icon to launch screenshots of the games."; // "none" = hide form
}

function initScreenShotView(){

	var f = document.getElementById( 'controls' );
	f.style.display = 'none'; // "none" = hide form
	
	var c = document.getElementById( 'screenshots' );
	c.style.display = 'block'; // "block" = show form
	
	
	
	var apps = new Image();
	apps.src = "./image/n97applications.png";
	
	var navi = new Image();
	navi.src = "./image/navi.png";
	
	var redPhone = new Image();
	redPhone.src = "./image/redPhoneButton.png"
	
	var shot = new Image();
	var num = ''+screenShotOnScreen;
	var ico = ''+iconSelected;
	
	shot.src = "./image/icon" + ico + "/icon" + ico +"Scrshot" + num + ".png";
	
	setCommentText(ico, num);
	
	if (document.images)
	{
    initDocumentImage(document.images.phone1, apps);
	initDocumentImage(document.images.naviButton1, navi);
	initDocumentImage(document.images.redPhoneButton1, redPhone);
	
	initDocumentImage(document.images.screenshot, shot);
	}
}

function scrShotPush(){

	if (screenShots <= 1) { return; }
	
	screenShotOnScreen += 1;
	
	if (screenShotOnScreen > screenShots) { screenShotOnScreen = 1; }
	
	var shot = new Image();
	var num = ''+screenShotOnScreen;
	var ico = ''+iconSelected;
	
	shot.src = "./image/icon" + ico + "/icon" + ico +"Scrshot" + num + ".png";
	
	setCommentText(ico, num);
	
	if (document.images)
	{
	initDocumentImage(document.images.screenshot, shot);
	}
}

// Chainreaxion
function icon1Push(){

	if (view != "Apps") { return; }
	
	view = "screenShots";
	
	if (alerts == 1) { alert("Icon1 push"); }
	iconSelected = 1;
	screenShots = 2;
	screenShotOnScreen = 1;
	
	initScreenShotView();
}

// BattleTetris ?
function icon2Push(){

	if (view != "Apps") { return; }
	
	view = "screenShots";
	
	if (alerts == 1) { alert("Icon2 push"); }
	iconSelected = 2;
	screenShots = 2;
	screenShotOnScreen = 1;
	
	initScreenShotView();
}

// Other ?
function icon3Push(){

	if (view != "Apps") { return; }

	view = "screenShots";
	
	if (alerts == 1) { alert("Icon3 push"); }
	iconSelected = 3;
	screenShots = 5;
	screenShotOnScreen = 1;
	
	initScreenShotView();
}

function icon4Push(){

	if (view != "Apps") { return; }

	view = "screenShots";
	
	if (alerts == 1) { alert("Icon4 push"); }
	iconSelected = 4;
	screenShots = 2;
	screenShotOnScreen = 1;
	
	initScreenShotView();
}

function icon5Push(){

	if (view != "Apps") { return; }

	view = "screenShots";
	
	if (alerts == 1) { alert("Icon5 push"); }
	iconSelected = 5;
	screenShots = 8;
	screenShotOnScreen = 1;
	
	initScreenShotView();

}
function icon6Push(){
	if (view != "Apps") { return; }
	view = "screenShots";
	if (alerts == 1) { alert("Icon6 push"); }
	iconSelected = 6;
	screenShots = 5;
	screenShotOnScreen = 1;
	initScreenShotView();
}
function icon7Push(){
	if (view != "Apps") { return; }
	view = "screenShots";
	if (alerts == 1) { alert("Icon7 push"); }
	iconSelected = 7;
	screenShots = 5;
	screenShotOnScreen = 1;
	initScreenShotView();
}
function icon8Push(){
	if (view != "Apps") { return; }
	view = "screenShots";
	if (alerts == 1) { alert("Icon8 push"); }
	iconSelected = 8;
	screenShots = 2;
	screenShotOnScreen = 1;
	initScreenShotView();
}
function icon9Push(){}

function setCommentText(iconNr, shotNr){

	var f = document.getElementById( 'text' );

	if (iconNr == 1 && shotNr == 1) // Chainreaxion, shot 1
	{
	f.textfield.value = "Chainreaxion game\n\nTry to make awesome chain reactions and blow as many moving trigger balls as you can! By achieving the goal, you can advance to the next level with more balls and difficulty. Watch out those balls marked with a skull. Those will decrease your blow up score. How good are you?\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 1 && shotNr == 2) // Chainreaxion, shot 2
	{
	f.textfield.value = "Chainreaxion game screenshot-2\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 2 && shotNr == 1) // Battle Blocks, shot 1
	{
	f.textfield.value = "Battle Blocks game\n\nBattle against your friends or computer in this fast paced arcade game. Create full rows of blocks to gain special actions, like the infamous Drunken attack, that can be used against your opponent. Speed is of the essence - you must hurry to gain the dynamites needed to blow up the brickwalls set up by your enemy!\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 2 && shotNr == 2) // Battle Blocks, shot 2
	{
	f.textfield.value = "Battle Blocks game screenshot-2\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 3 && shotNr == 1) // MotionSpeed, shot 1
	{
	f.textfield.value = "MotionSpeed game\n\nMotionSpeed is a game where you need to have excellent reflexes and speed. Try to get as many correct pushes as you can. There is not only 1 four-button level, there are 20 levels with 2,4,8 and 12 buttons ! Each level has a centain goal that you must reach to advance to the next level! How quick are you with 12 buttons? Check it on YouTube: http://www.youtube.com/watch?v=nuZBYJ5kBDk\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 3 && shotNr == 2) // MotionSpeed, shot 2
	{
	f.textfield.value = "MotionSpeed game screenshot-2\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 3 && shotNr == 3) // MotionSpeed, shot 3
	{
	f.textfield.value = "MotionSpeed game screenshot-3\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 3 && shotNr == 4) // MotionSpeed, shot 4
	{
	f.textfield.value = "MotionSpeed game screenshot-4\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 3 && shotNr == 5) // MotionSpeed, shot 5
	{
	f.textfield.value = "MotionSpeed game screenshot-5\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 4 && shotNr == 1) // Maya bubbles, shot 1
	{
	f.textfield.value = "Maya Bubbles Touch\n\nMaya Bubbles has the awesome gameplay as the most popular versions of Bubbles have! The idea is to create a group of at least three bubbles to explode them. Bubbles that are not attached to anything get dropped down. Each dropped bubble gives you an extra bubble to shoot! Use rainbow bubbles to explode multiple colors at once.\n\n\nPress red phone to go back."; // "none" = hide form
	}
	else if (iconNr == 4 && shotNr == 2) // Maya bubbles, shot 2
	{
	f.textfield.value = "Maya bubbles game screenshot-2\n\n\nPress red phone to go back."; // "none" = hide form
	}

 else if (iconNr == 5) // Marble Maze
	{
	f.textfield.value = "Marble Maze 2 touch\n\nSecond version of the famous Marble Maze game is finally here! Here's the Marble Maze 2. It has 70 new challenges and new features! Are you able to steer the ball into it's goal?\n\n\nPress red phone to go back."; // "none" = hide form
	} else if (iconNr == 6) // Marble Maze
	{
	f.textfield.value = "Air Hockey Touch\n\nAir Hockey Touch is finally here! The legendary table game is now available in your pocket anytime you want to play! Responsive touch, good gameplay, and unlimited AI opponents will keep you playing for a long time.\n\n\nPress red phone to go back."; // "none" = hide form
	} else if ( iconNr == 7) // Miner Mania
	{
	f.textfield.value = "Collect diamonds and other valuable rocks in this mining game to get points, but avoid worthless rocks, since you lose points. Try to be the best in the world, in the global high-score list!\n\n\nPress red phone to go back."; // "none" = hide form
	} else if ( iconNr == 8) // Soccer Bounce
	{
	f.textfield.value = "Soccer Bounce is a game where you can try to bounce a soccer ball as many times as you possible can with your fingertip. Try to be the best in the world and qualify in the top1 place in global online score list!\n\n\nPress red phone to go back."; // "none" = hide form
	}


}

function setPosition(){

    var width = document.body.clientWidth;

    var leftAdd = (width - 750) / 2;

    if (leftAdd < 0) { leftAdd = 0; }

    var f = document.getElementById( 'controls' );
    f.style.left = leftAdd;

    var c = document.getElementById( 'screenshots' );
    c.style.left = leftAdd;

    var t = document.getElementById( 'text' );
    t.style.left = 350 + leftAdd;

}

