/* Initialisation dynamique */

$(document).ready(function() {
	/* Logo */
	
	if($.browser.mozilla){
		$(".ligne_deux").css("margin-top","21%");
		$(".ligne_trois").css("margin-top","42%");
		$(".ligne_quatre").css("margin-top","63%");
		$(".ligne_cinq").css("margin-top","84%");
		$(".ligne_six").css("margin-top","105%");
	}
	
	$(".carre").width('18%');
	$(".carre").height('16%');

	$("#logo").width('6%');
	$("#logo").height($("#logo").width()*(6/5));
	$("#logo").css("margin-top", 70+(750-window.innerWidth)/22+"px");
	
	$("#logo").css("margin-left", -($("#logo").width()/2));
	
	$("#info").css("bottom", -(750-window.innerWidth)/6);
	$("#help").css("bottom", -(750-window.innerWidth)/6);
	
	/* Menu */
	
	$("#menu").css("margin-top", 205-(750-window.innerWidth)/18+"px");
	$("#menu ul li:nth-child(2)").css("margin-top", 32-(750-window.innerWidth)/30+"px");
	
	/* Help */

	var help = false;

	$("#help").click(function(){
		if( help == false ){
			help = true;
			$("#help").animate({ width: 203+"px"}, 600);
		}
		else{
			help = false;
			$("#help").animate({ width: 10+"px"}, 600);
		}
	});
	
	var mouse_state = 1;

	var timer = setInterval(function(){
		$("#scroll").attr({src:'img/main-souris'+mouse_state+'.png'});
		if (mouse_state == 1){
			mouse_state = 2;
			$("#scroll").css('bottom','10%');
		}else if(mouse_state == 2){
			mouse_state = 3;
		}else{
			mouse_state = 1;
			$("#scroll").css('bottom','13%');
		}
	},500);
});

/* Test du clic */

var clic = false;

$(document).mousedown(function(){
	clic = true;
	return false;
});
$(document).mouseup(function(){
	clic = false;
	return false;
});

/* Stop-motion */
	
document.onmousemove = getMouseY;
var tempY = 0;

$("#menu ul li").css("opacity", "0");

var hide_li_un = false;
var hide_li_deux = false;

function getMouseY(e) {
	tempY = e.pageY;
	if (!clic && $("body").hasClass("bckgrd13")){
		/*alert ("lol");*/
		location.href= "stopmotion2";
	} else if (!clic && $("body").hasClass("bckgrd11")){
		location.href= "http://blog.avgs.ca";
	} else if (!clic){
		return false;
	}
	
	if (tempY < 0){tempY = 0};
	
	if ( tempY>=(window.innerHeight*0.6)){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd1");
	}
	else if ( tempY<(window.innerHeight*0.6) && tempY>=(window.innerHeight*0.58) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd2");
	}
	else if ( tempY<(window.innerHeight*0.58) && tempY>=(window.innerHeight*0.56) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd3");
	}
	else if ( tempY<(window.innerHeight*0.56) && tempY>=(window.innerHeight*0.54) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd4");
	}
	else if ( tempY<(window.innerHeight*0.54) && tempY>=(window.innerHeight*0.52) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd5");
	}
	else if ( tempY<(window.innerHeight*0.52) && tempY>=(window.innerHeight*0.5) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd6");
	}
	else if ( tempY<(window.innerHeight*0.5) && tempY>=(window.innerHeight*0.48) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd7");
	}
	else if ( tempY<(window.innerHeight*0.48) && tempY>=(window.innerHeight*0.46) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd8");	
	}
	else if ( tempY<(window.innerHeight*0.46) && tempY>=(window.innerHeight*0.44) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd9");
		
		if( hide_li_un == true){
			hide_li_un = false;
			$("#menu ul li:nth-child(2)").animate({ left: -window.innerWidth*0.03+"px", opacity: 0 }, 600);
		}
	}
	
	else if ( tempY<(window.innerHeight*0.44) && tempY>=(window.innerHeight*0.42) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd10");
		
		if( hide_li_un == true){
			hide_li_un = false;
			$("#menu ul li:nth-child(2)").animate({ left: -window.innerWidth*0.03+"px", opacity: 0 }, 600);
		}
	}
	
	/* slide 1 */
	else if ( tempY<(window.innerHeight*0.42) && tempY>=(window.innerHeight*0.4) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd11");
		
		if( hide_li_un == false){
			hide_li_un = true;
			$("#menu ul li:nth-child(2)").animate({ left: window.innerWidth*0.03+"px", opacity: 0.5 }, 600);
			$("#menu ul li:nth-child(1)").animate({ left: -window.innerWidth*0.03+"px", opacity: 0 }, 600);
		}
	}
	
	/* slide 2 */
	else if ( tempY<(window.innerHeight*0.4) && tempY>=(window.innerHeight*0.38) ){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd12");
		
		if( hide_li_un == true){
			hide_li_un = false;
			$("#menu ul li:nth-child(2)").animate({ left: -window.innerWidth*0.03+"px", opacity: 0 }, 600);
		}
		
		if( hide_li_deux == true){
			hide_li_deux = false;
			$("#menu ul li:nth-child(1)").animate({ left: -window.innerWidth*0.03+"px", opacity: 0 }, 600);
		}
	}
	
	/* slide 3 */
	else if ( tempY<(window.innerHeight*0.38)){
		for(i=0; i<=13 ; i++){ $("body").removeClass("bckgrd"+i); }
		$("body").addClass("bckgrd13");
		
		if( hide_li_deux == false){
			hide_li_deux = true;
			$("#menu ul li:nth-child(1)").animate({ left: window.innerWidth*0.03+"px", opacity: 0.5 }, 600);
			$("#menu ul li:nth-child(2)").animate({ left: -window.innerWidth*0.03+"px", opacity: 0 }, 600);
		}
	}	
	return true;
}

/* Resize logo en fonction de la résolution */

$(window).resize(function() {
	$(".carre").width('18%');
	$(".carre").height('16%');

	$("#logo").width('6%');
	$("#logo").height($("#logo").width()*(6/5));
	$("#logo").css("margin-top", 70+(750-window.innerWidth)/22+"px");
	
	$("#logo").css("margin-left", -($("#logo").width()/2));
	
	$("#info").css("bottom", -(750-window.innerWidth)/6);
	
	$("#menu").css("margin-top", 205-(750-window.innerWidth)/22+"px");
	$("#menu ul li:nth-child(2)").css("margin-top", 32-(750-window.innerWidth)/22+"px");
});
