// JavaScript Document

$(document).ready(function() {
	header();
	$("#machine").animate({top:"136px"},1000,"easeOutBounce")
	$("#boite").animate({top:"136px"},1000,"easeOutBounce")
	$("#tuyau").animate({top:"385px"},1000,"easeOutBounce")
	$("#piston").animate({top:"369px"},1000,"easeOutBounce")
	setTimeout("haricots()",400);
	setTimeout("animation()",1500);
	
	$("#btn-accueil").click(function() {
		changeAccueil("on");
		changeSociete("off");
		changeJeux("off");
		changeContact("off");
		societeOut();
		jeuxOut();
		fichejeuOut();
		contactOut();
	});
	
	$("#btn-societe").click(function() {
		changeAccueil("off");
		changeJeux("off");
		changeContact("off");
		setTimeout("societeIn()",300);
		jeuxOut();
		fichejeuOut();
		contactOut();
	});
	
	$("#btn-jeux").click(function() {
		changeAccueil("off");
		changeSociete("off");
		changeContact("off");
		setTimeout("jeuxIn()",300);
		fichejeuOut();
		societeOut();
		contactOut();
	});
	
	$("#jeux-liste-jeu-1").click(function() {
		setTimeout("fichejeuIn(1)",300);
		jeuxOut();
	});
	$("#jeux-liste-jeu-2").click(function() {
		setTimeout("fichejeuIn(2)",300);
		jeuxOut();
	});
	$("#jeux-liste-jeu-3").click(function() {
		setTimeout("fichejeuIn(3)",300);
		jeuxOut();
	});
	$("#jeux-liste-jeu-4").click(function() {
		setTimeout("fichejeuIn(4)",300);
		jeuxOut();
	});
	$("#jeux-liste-jeu-5").click(function() {
		setTimeout("fichejeuIn(5)",300);
		jeuxOut();
	});
	
	$("#btn-contact").click(function() {
		changeAccueil("off");
		changeJeux("off");
		changeSociete("off");
		setTimeout("contactIn()",300);
		societeOut();
		jeuxOut();
		fichejeuOut();
	});
	
	$(".btn-fermer").click(function() {
		changeContact("off");
		changeAccueil("off");
		changeJeux("off");
		changeSociete("off");
		societeOut();
		jeuxOut();
		contactOut();
		fichejeuOut();
	});
	$(".fiche-jeu .btn-fermer").click(function() {
		setTimeout("jeuxIn()",300);
		fichejeuOut();
	});
	
});

function preloadImages() {
    var preloaded = new Array();
    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
}

function haricots() {
	$("#haricots").animate({top:"450px"},50,"linear").animate({top:"467px"},500,"easeOutBounce")
}

function header() {
	logo();
	dirigeable();
}
	

// ANIMATION ELEMENTS

function animation() {
	conserve();
	setTimeout("arcenciel()",1600);
	setTimeout("fumee1()",2900);
	setTimeout("fumee2()",3100);
	tuyau();
	setTimeout("coulis()",3600);
	setTimeout("puree()",3600);
	setTimeout("piston()",8600);
	setTimeout("transporteur()",8900);
	setTimeout("animation()",15000);
	
}

function logo() {
	$("#logo").animate({top:"13px"},2000,"linear").animate({top:"0px"},2000,"linear")
	setTimeout("logo()",0);	
}

function changeDirigeable(num) {
	document.getElementById("dirigeable").style.backgroundImage = "url(images/dirigeable"+num+".png)";
}

function dirigeable() {
	$("#dirigeable").animate({left:"850px"},30000,"linear",function(){changeDirigeable(2);}).animate({left:"50px"},30000,"linear",function(){changeDirigeable(1);})
	setTimeout("dirigeable()",0);	
}

function arcenciel() {
	$("#arcenciel").animate({top:"170px",height:"50px"},0,"linear").animate({top:"208px",height:"124px"},400,"linear").animate({top:"208px",height:"124px"},500,"linear").animate({top:"340px",height:"50px"},400,"linear")	
}

function fumee1() {
	$("#fumee1").animate({top:"350px",left:"370px"},0,"linear").fadeIn(0,1).animate({top:"283px",left:"360px"},600,"easeOutBack").animate({top:"283px",left:"360px"},500,"linear").fadeOut(1000)	
}
function fumee2() {
	$("#fumee2").animate({top:"350px",left:"380px"},0,"linear").fadeIn(0,1).animate({top:"318px",left:"374px"},600,"easeOutBack").animate({top:"318px",left:"374px"},500,"linear").fadeOut(1000)
}

function tuyau() {
	$("#tuyau").animate({top:"390px"},200,"easeOutBack").animate({top:"385px"},200,"linear")
}

function changeConserve(etat) {
	document.getElementById("conserve").style.backgroundImage = "url(images/conserve-"+etat+".png)";
}
function conserve() {
	$("#conserve").animate({top:"365px",left:"340px"},0,"linear").animate({top:"426px",left:"340px"},600,"easeOutBounce").animate({left:"398px"},1000,"easeInOutSine").animate({left:"398px"},3500,"easeInOutSine",function(){changeConserve("pleine");}).animate({left:"398px"},500,"easeInOutSine").animate({left:"570px"},3000,"easeInOutSine").animate({left:"570px"},2000,"easeInOutSine",function(){changeConserve("vide");}).animate({left:"632px"},1000,"easeInSine").animate({top:"446px",left:"635px"},300,"linear").animate({top:"446px",left:"635px"},500,"linear").animate({top:"365px",left:"340px"},0,"linear")
}

function coulis() {
	$("#coulis").animate({top:"370px"},0,"linear").animate({top:"421px"},500,"linear").animate({top:"421px"},500,"linear").animate({top:"460px"},700,"linear")
}

function puree() {
	$("#puree").animate({top:"450px",left:"398px"},0,"linear").animate({top:"421px"},1000,"easeOutSine").animate({top:"421px"},500,"linear").animate({top:"450px",left:"398px"},0,"linear")
}

function piston() {
	$("#piston").animate({top:"390px"},200,"easeOutBounce").animate({top:"369px"},1000,"linear")
}

function changeTransporteur(name) {
	document.getElementById("transporteur").style.backgroundImage = "url(images/transporteur-"+name+".png)";
}
function transporteur() {
	$("#transporteur").animate({top:"432px",left:"530px"},0,"linear",function(){changeTransporteur("sol");}).animate({top:"452px",left:"634px"},2000,"easeOutSine").animate({top:"452px",left:"634px"},1230,"easeOutSine",function(){changeTransporteur("charge");}).animate({top:"452px",left:"634px"},1300,"easeOutSine").animate({top:"452px",left:"634px"},0,"linear",function(){changeTransporteur("air");}).animate({top:"-90px",left:"900px"},1000,"easeInQuad");	
}

// -------------------------------

// ANIMATION MENU

function changeAccueil(etat) {
	document.getElementById("btn-accueil").style.backgroundImage = "url(images/btn-accueil-"+etat+".png)";
}

function changeSociete(etat) {
	document.getElementById("btn-societe").style.backgroundImage = "url(images/btn-societe-"+etat+".png)";
}

function changeJeux(etat) {
	document.getElementById("btn-jeux").style.backgroundImage = "url(images/btn-jeux-"+etat+".png)";
}

function changeContact(etat) {
	document.getElementById("btn-contact").style.backgroundImage = "url(images/btn-contact-"+etat+".png)";
}

// -------------------------------

// ANIMATION CATEGORIES

function societeIn() {
	changeSociete("on");
	$("#societe").animate({top:"-88px"},1000,"easeOutBounce")
}
function societeOut() {
	$("#societe").animate({top:"-615px"},400,"easeInBack")
}

function jeuxIn() {
	changeJeux("on");
	$("#jeux").animate({top:"-88px"},1000,"easeOutBounce")
}
function jeuxOut() {
	$("#jeux").animate({top:"-615px"},400,"easeInBack")
}

function contactIn() {
	changeContact("on");
	$("#contact").animate({top:"-88px"},1000,"easeOutBounce")
}
function contactOut() {
	$("#contact").animate({top:"-615px"},400,"easeInBack")
}

// -------------------------------

// ANIMATION FICHE JEU

function fichejeuIn(num) {
	$("#fiche-jeu-"+num).animate({top:"-100px"},500,"easeOutBack")
}
function fichejeuOut() {
	$(".fiche-jeu").animate({top:"-615px"},400,"easeInBack")
}

function navPrevious(num) {
	var a=num-1;
	setTimeout("fichejeuIn("+a+")",500);
	$("#fiche-jeu-"+num).animate({top:"-615px"},400,"easeInBack")
}
function navNext(num) {
	var a=num+1;
	setTimeout("fichejeuIn("+a+")",500);
	$("#fiche-jeu-"+num).animate({top:"-615px"},400,"easeInBack")
}
