/**
 * Variables
 */
//DIVs positions
var counter=0;
var DIV_HOME = counter++;
var DIV_ABOUT = counter++;
var DIV_DEV = counter++;
var DIV_CONSULTING = counter++;
var DIV_PRODUCTS = counter++;
var DIV_BUILT = counter++;
var DIV_CONTAC = counter++;
//DIVs width
var DIV_WIDTH = 2320;
//Timing for animation
var TIMING = 600;
//Continer id
var CONTINER = "#continer";
//Actual location
var LOCATION=DIV_HOME;

/**
 * Method for the horizontal animation
 * @param divName the name of the Div
 */
function animateTo(divName) {
	try{
	if(divName=="about"){
		LOCATION=DIV_ABOUT;
		$(CONTINER).animate({ 
			left: (-DIV_WIDTH*DIV_ABOUT)+"px"
		}, TIMING );
	}
	else if(divName=="dev"){
		LOCATION=DIV_DEV;
	      $(CONTINER).animate({ 
	          left: (-DIV_WIDTH*DIV_DEV)+"px"
	        }, TIMING );
	}
	else if(divName=="consulting"){
		LOCATION=DIV_CONSULTING;
	      $(CONTINER).animate({ 
	          left: (-DIV_WIDTH*DIV_CONSULTING)+"px"
	        }, TIMING );
	}
	else if(divName=="products"){
		LOCATION=DIV_PRODUCTS;
	      $(CONTINER).animate({ 
	          left: (-DIV_WIDTH*DIV_PRODUCTS)+"px"
	        }, TIMING );
	}
	else if(divName=="built"){
		LOCATION=DIV_BUILT;
	      $(CONTINER).animate({ 
	          left: (-DIV_WIDTH*DIV_BUILT)+"px"
	        }, TIMING );
	}
	else if(divName=="contact"){
		LOCATION=DIV_CONTAC;
	      $(CONTINER).animate({ 
	          left: (-DIV_WIDTH*DIV_CONTAC)+"px"
	        }, TIMING );
	}
	else{
		LOCATION=DIV_HOME;
		/*Home or error*/
      $(CONTINER).animate({ 
          left: (-DIV_WIDTH*DIV_HOME)+"px"
        }, TIMING );
	}
	}catch (e) {
		alert("animateTo:"+e.description);
	}
}

/**
 * Method used by the keyboard listener
 * @param divNumber the number of the Div to move
 */
function animateToNumber(divNumber){
	try{
		if(divNumber==DIV_ABOUT){
			animateTo("about");
			pageTracker._trackEvent('About','KeyBoard');
		}else if(divNumber==DIV_DEV){
			animateTo("dev");
			pageTracker._trackEvent('DevWeb','KeyBoard');
		}else if(divNumber==DIV_CONSULTING){
			animateTo("consulting");
			pageTracker._trackEvent('Consulting','KeyBoard');
		}else if(divNumber==DIV_PRODUCTS){
			animateTo("products");
			pageTracker._trackEvent('Products','KeyBoard');
		}else if(divNumber==DIV_BUILT){
			animateTo("built");
			pageTracker._trackEvent('Built','KeyBoard');
		}else if(divNumber==DIV_CONTAC){
			animateTo("contact");
			pageTracker._trackEvent('Contact','KeyBoard');
		}else{
			animateTo("home");
			pageTracker._trackEvent('Home','KeyBoard');
		}
	}catch (e) {
		//alert("animateToNumber:"+e.description+" "+divNumer+"="+LOCATION+"+1");
	}
	
}

if((navigator.appName!="Microsoft Internet Explorer")){
	try{
		Cufon.set('fontFamily', 'journal');
		Cufon.replace("#beta",{fontSize:'30px',fontWeight:"bold"});
		Cufon.set('fontFamily', 'quicksand');
		Cufon.replace("#home",{fontSize:'90px'});
		Cufon.replace("#header ul a",{fontSize:'20px',fontWeight:"bold"});
		Cufon.replace("#footer");
		Cufon.replace("#continer");
		$(document).ready(function(){
    		$("#beta").css({"top":"0"});
    		/*$("div.menu-section p").css({"margin":"0"});*/
    		/*setTimeout("window.scrollTo(1,0)",1000);setTimeout("$('#beta').fadeIn(3000);",2000);
    		setTimeout("$('div#header ul').fadeIn(3000);",2000);
    		setTimeout("$('#home p').fadeIn(6000);",2500);
    		setTimeout("$('#footer').fadeIn(3000);",2000);*/
		});
	}catch(error){
	}
}else{
}


/*Key board listening*/
function keyListener(e){
	try{
	   if(!e){
	      e = window.event;
	      //for IE
	   }
	   if(e.keyCode==37){
		   window.scrollTo(1,0);
		   if(LOCATION>DIV_HOME){
			   animateToNumber(LOCATION-1);
//			   //keyCode 37 is left arrow
		   }
	   }
	   if(e.keyCode==39){
		   window.scrollTo(1,0);
		   if(LOCATION<DIV_CONTAC){
			   animateToNumber(LOCATION+1);
//			   //keyCode 39 is right arrow
		   }
	   }
	}catch(err){
		//alert(err.description+":LOCATION="+LOCATION+"-DIV_CONTAC="+DIV_CONTAC);
	}
}
document.onkeydown = keyListener; 
