	//pre-loader
	$("#page").hide();
	$("#content").hide();
	$("body").append('<div id="wait"></div>');
	//$("#wait").load("includes/wait.php");


$(document).ready(function(){



	var pagedata=new Array();
	var titles=new Array();
	var fsize=150;

	
	function resize(){
		var winH=window.innerHeight;
		var winW=window.innerWidth;
		var winP=winW/winH;
		
		var backH=$("#back").attr("height");
		var backW=$("#back").attr("width");
		var backP=backW/backH;
		
		if(winP>backP){
			rapport=winH/backH;
		} else {
			rapport=winW/backW;
		};
		$("#page").width(rapport*backW);
		$("#page").height(rapport*backH);
		//console.log(fsize+" "+rapport);
		$("body").css("font-size",(rapport*fsize)+"%");
		
	};
	
	function resetCSS(){
		$("li.main").not(".curr").each(function(){
			$(this).animate({left:'0%'});
		});
		$("li.main.curr").animate({left:'10%'});
	};

function changePage(ref){
		myhref=$(ref).attr("href");
		if($(ref).attr("href")!=currentPage){
			$("li#"+currentPage).removeClass("curr").not(".sub").animate({left:0},144);
			$("li#"+myhref).addClass("curr").animate({left:'10%'},233);
			currentPage=$(ref).attr("href");
			//$("#content").load("includes/"+currentPage+".php");
//			console.log(pagedata[$(this).attr("id")].responseText);
			history.pushState(null, "", myhref);
			document.title=titles[myhref];
			$("#content").fadeOut(500,function(){
				$("#content").empty().append(pagedata[myhref].responseText).fadeIn(500);
				_gaq.push(['_setAccount', 'UA-24868342-1']);
				_gaq.push(['_trackPageview', '/'+myhref]);

				$("a.internal").click(function(event){
					changePage(this);
					event.preventDefault();
				});
			});
		};	
};



	function loadall(){
		$("a.menulink").each(function(){
			pagedata[$(this).attr("id")]=$.get("includes/"+$(this).attr("id")+".php");			
		});
		titles["mission"]="Mission | Les Productions Hugocentrique";
		titles["services"]="Services | Les Productions Hugocentrique";
		titles["portefolio"]="Portefolio | Les Productions Hugocentrique";
		titles["contact"]="Contact | Les Productions Hugocentrique";
		//console.log(test);
		

	};
	

	$("a.menulink").click(function(event){

/*		myhref=$(this).attr("href");
		if($(this).attr("href")!=currentPage){
			$("li#"+currentPage).removeClass("curr").not(".sub").animate({left:0},144);
			$(this).parent().addClass("curr");
			currentPage=$(this).attr("href");
			//$("#content").load("includes/"+currentPage+".php");
//			console.log(pagedata[$(this).attr("id")].responseText);
			$("#content").fadeOut(500,function(){
				$("#content").empty().append(pagedata[myhref].responseText).fadeIn(500);
				});
		};
		*/
		changePage(this);
		event.preventDefault();
	});

	$("a.internal").click(function(event){
		changePage(this);
		event.preventDefault();
	});

		
	$("li.main").hover(function(){
		$("li.main#"+$(this).attr("id")).not(".curr").animate({left:'10%'},233);
	},function(){
		$("li.main#"+$(this).attr("id")).not(".curr").animate({left:0},144);
	});

	resize();
	resetCSS();
	window.onresize=resize;	
	loadall();
	history.pushState(null, "", currentPage);

	

});
/*		$("a.internal").click(function(event){
				changePage(this);
				console.log("pout");
				event.preventDefault();
			});
*/

$(window).load(function(){
	//quand le pre-load est terminé
	$("#wait").fadeOut(1000);
	$("#page").fadeIn(1000);
	$("#content").fadeIn(100);
});
