// JavaScript Document

var navArr = [];
var currentlablesArr = [];
var pageArr = [];
var activepage = -1;
var oldpage = -1;
var beeingPushed = "next";
var oldpage_content = "";
var imageFiles = new Array("images/all_costomers.png", "images/contact_blackcircle_shadow.png", "images/contact_blackcircle_shadow_blur.png", "images/contact_redcircle_shadow_blur.png", "images/contact_redcircle_shadow.png", "images/cph_map.jpg", "images/aah_map.jpg", "images/logo.png", "images/about_continiue_red.png", "images/about_continiue_black.png", "images/about_back_red.png", "images/about_back_black.png");




///////////////* PRELOADING IMAGES *//////////////

$(document).ready(function()
{
	
	jQuery.imgpreload(imageFiles,
	{
			all: function()
			{
				$("body").fixPng();
			
				initAbout();
				initCostomers();
				initContact();
				
				initTopNavigation();
				initCenterNavigation();
				initContent();
				//initGnomSplash();
				
			}
	});			
});












///////////////* TOP NAVIGATION *//////////////

function initTopNavigation()
{
	navArr.push("#about");
	navArr.push("#costomers");
	navArr.push("#contact");
	
	currentlablesArr.push("#current_about");
	currentlablesArr.push("#current_costomers");
	currentlablesArr.push("#current_contact");
	
	
		
	$(navArr[0] + ',' + navArr[1] + ',' + navArr[2]).hover(
		function () 
		{
			if("#" + $(this).attr('id') != navArr[activepage])	$(this).addClass("top_navigation_hover");
		},
		function () 
		{
			if("#" + $(this).attr('id') != navArr[activepage])	$(this).removeClass("top_navigation_hover");
		}
	);
	
	
	$(navArr[0] + ',' + navArr[1] + ',' + navArr[2]).click(
		function()
		{
			if($(this).attr('id') == 'about') changePage(0);
			else if($(this).attr('id') == 'costomers') changePage(1);
			else changePage(2);	
		}
	);	
}






///////////////* GNOM SPLASH *//////////////

function initGnomSplash()
{
	$("#gnom_splash_img").hover(function()
	{
		$(this).animate({ 'width':155, 'height':154, 'margin-left':8, 'margin-top':8 }, 200, 'easeOutBack', function(){});
	},
	function()
	{
		$(this).animate({ 'width':173, 'height':172, 'margin-left':0, 'margin-top':0 }, 200, 'easeOutBack', function(){});
	});
}







///////////////* CENTER NAVIGATION *//////////////

function initCenterNavigation()
{
	// HIDES THE ELEMENTS THAT NEEDS TO BE HIDDEN FROM THE START
	$("#next_circle").hide(100);
	$("#previous_circle").hide(100);
	$("#next_arrow_big, #next_lable, #previous_arrow_big, #previous_lable").css({ 'opacity' : 0 });
	
	$(currentlablesArr[0]).css({'opacity':0});
	$(currentlablesArr[1]).css({'opacity':0});
	$(currentlablesArr[2]).css({'opacity':0});
	
	
	// HOVER AND CLICK FOR THE NEXT & PREVIOUS BUTTONS
	$("#next_hitarea").hover(
	function()
	{
		$("#next_arrow_small").animate({'left' : 120, 'opacity' : 0}, 300, function(){});
		$("#next_arrow_big").animate({'left' : 108, 'opacity' : 1}, 300, function(){});
		$("#next_circle").delay(100).show("scale", 200);
		centerNavigationNextLable("show");
	},
	function()
	{
		$("#next_arrow_small").animate({'left' : 110, 'opacity' : 1}, 200, function(){});
		$("#next_arrow_big").animate({'left' : 98, 'opacity' : 0}, 300, function(){});
		$("#next_circle").hide("scale", 200);
		centerNavigationNextLable("hide");
	});
	
	
	$("#next_hitarea").click(
	function()
	{
		centerNavigationNextLable("hide");
		
		beeingPushed = "next";
		
		var nextnr = activepage;
		++nextnr;
		nextnr = nextnr > 2 ? 0 : nextnr;
		changePage(nextnr);
	});
	
	
	
	
	
	

	
	$("#previous_hitarea").hover(
	function()
	{
		$("#previous_arrow_small").animate({'left' : 0, 'opacity' : 0}, 300, function(){});
		$("#previous_arrow_big").animate({'left' : 3, 'opacity' : 1}, 300, function(){});
		$("#previous_circle").delay(100).show("scale", 200);
		centerNavigationPreviousLable("show");
	},
	function()
	{
		$("#previous_arrow_small").animate({'left' : 10, 'opacity' : 1}, 200, function(){});
		$("#previous_arrow_big").animate({'left' : 13, 'opacity' : 0}, 300, function(){});
		$("#previous_circle").hide("scale", 200);
		centerNavigationPreviousLable("hide");
	});
	
	
	$("#previous_hitarea").click(
	function()
	{
		centerNavigationPreviousLable("hide");
		
		beeingPushed = "previous";
		
		var nextnr = activepage;
		--nextnr;
		nextnr = nextnr < 0 ? 2 : nextnr;
		changePage(nextnr);
	});
}





function centerNavigationNextLable(state)
{
	var lables = ["#next_lable0", "#next_lable1", "#next_lable2"];
	$(lables[0]).css({'opacity':0});
	$(lables[1]).css({'opacity':0});
	$(lables[2]).css({'opacity':0});
	
	if(state == "show")
	{
		$("#next_lable").delay(300).animate({ 'opacity':1, 'left':0}, 400, 'easeOutExpo', function(){});
		$(lables[activepage]).css({'opacity':1});
	}
	else if(state == "hide")
	{
		$("#next_lable").animate({ 'opacity':0, 'left':30}, 300, 'easeInExpo', function(){});
	}	
}





function centerNavigationPreviousLable(state)
{
	var lables = ["#previous_lable0", "#previous_lable1", "#previous_lable2"];
	$(lables[0]).css({'opacity':0});
	$(lables[1]).css({'opacity':0});
	$(lables[2]).css({'opacity':0});
	
	if(state == "show")
	{
		$("#previous_lable").delay(300).animate({ 'opacity':1, 'left':45}, 400, 'easeOutExpo', function(){});
		$(lables[activepage]).css({'opacity':1});
	}
	else if(state == "hide")
	{
		$("#previous_lable").animate({ 'opacity':0, 'left':10}, 300, 'easeInExpo', function(){});
	}	
}






function initContent()
{
	pageArr.push("#about_content");
	pageArr.push("#costomers_content");
	pageArr.push("#contact_content");
	
	$(pageArr[0]).slideUp(0);
	$(pageArr[1]).slideUp(0);
	$(pageArr[2]).slideUp(0);
	
	changePage(2);
}




///////////////* CHANGE PAGES WITH A NUMBER *//////////////

function changePage(num)
{
	// HANDLES THE TOP NAVIGATION
	if(num != -1 && num != activepage)
	{	
		$(navArr[activepage]).animate({ backgroundPosition: '50% 15px' }, 400);	
		$(navArr[activepage]).removeClass("top_navigation_hover");
	}
	
	if(num != activepage)
	{
		activepage = num;
		$(navArr[activepage]).animate({ backgroundPosition: '50% 25px' }, 400);	
		$(navArr[activepage]).addClass("top_navigation_hover");	
		
		centerCurrent();
		
		updateContent();
	}	
	
	
}



function centerCurrent()
{
	var centerX;
	var lableOutX;
	var lableInX;
	
	
	if(oldpage != -1)
	{
		if(beeingPushed == "next")
		{
			centerX = $("#currentpage").width()/2 - $(currentlablesArr[oldpage]).width()/2;
			lableOutX = centerX - 150;
			$(currentlablesArr[oldpage]).animate({ 'opacity':0, 'left':lableOutX}, 400, 'easeInExpo', function(){});
			
			centerX = $("#currentpage").width()/2 - $(currentlablesArr[activepage]).width()/2;
			lableInX = centerX + 150;
			$(currentlablesArr[activepage]).css({ 'left' : lableInX});
			$(currentlablesArr[activepage]).delay(300).animate({ 'opacity':1, 'left':centerX}, 400, 'easeOutExpo', function(){});
		}
		else
		{
			centerX = $("#currentpage").width()/2 - $(currentlablesArr[oldpage]).width()/2;
			lableOutX = centerX + 150;
			$(currentlablesArr[oldpage]).animate({ 'opacity':0, 'left':lableOutX}, 400, 'easeInExpo', function(){});
			
			centerX = $("#currentpage").width()/2 - $(currentlablesArr[activepage]).width()/2;
			lableInX = centerX - 150;
			$(currentlablesArr[activepage]).css({ 'left' : lableInX});
			$(currentlablesArr[activepage]).delay(300).animate({ 'opacity':1, 'left':centerX}, 400, 'easeOutExpo', function(){});
		}
	}
	
	
	else
	{
		centerX = $("#currentpage").width()/2 - $(currentlablesArr[activepage]).width()/2;
		lableInX = centerX + 150;
		$(currentlablesArr[activepage]).delay(300).animate({ 'opacity':1, 'left':centerX}, 400, 'easeOutExpo', function(){});
	}
	
	
	
	oldpage = activepage;
}







///////////////* CHANGE PAGES WITH A NUMBER *//////////////

function updateContent()
{
	if(oldpage_content != "")
	{
		switch(activepage)
		{
			case 0:
					about_reset();
					break;
			
			case 1:
					break;
			
			case 2:
					contact_resetCircles();
					break;	
		}
		
		
		$(oldpage_content).slideUp(500, 
		function()
		{
			$(pageArr[activepage]).slideDown(500);	
		});	
	}
	
		else
		{
			$("body").css({'visibility':'visible'})
			$(pageArr[activepage]).slideDown(500);
		}
	
	
	oldpage_content = pageArr[activepage];
}




