$(document).ready(function(){

	Cufon.replace('#header ul li.cufon',{ fontFamily: 'Delicious' , hover: true});
	Cufon.replace('h1',{ fontFamily: 'Anivers' });
	Cufon.replace('h2',{ fontFamily: 'Anivers' });
	Cufon.replace('h3',{ fontFamily: 'Anivers' });
		
	if($('.valeurs', '#bandeau').length) {

		$('.content', '#quote_1').corner();
		$('.content', '#quote_2').corner();
		$('.content', '#quote_3').corner();
	
	}
	
	if($('.carriere', '#bandeau').length) {
		setupJobs();
		setupOffresCarriere();
		
	}
	
	if($('.home', '#bandeau').length) {
		setupJobs();
		setupOffresHome();
	}

});


//PUSHS HOME//



$("#push1").mouseenter(
	function () {
		$("#push1 .gauche").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_g.jpg) no-repeat #FFFFFF", "height" : "262px"});
		$("#push1 .droite").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_d.jpg) no-repeat #FFFFFF", "height" : "262px"});	
		$("#push1 .milieu").css ({"margin-top" : "-11px", "border-top" : "5px solid #ef862d" });
		$("#push2 .gauche").css ({"width" : "0px"});
		$("#push2 .droite").css ({"width" : "0px"});
		$("#push2 .milieu").css ({"margin-top" : "0px", "border-top" : "0px solid #ef862d"});		
	}).mouseleave(function() {
		$("#push1 .gauche").css ({"width" : "0px"});
		$("#push1 .droite").css ({"width" : "0px"});	
		$("#push1 .milieu").css ({"margin-top" : "0px", "border-top" : "0px solid #ef862d"});	
		$("#push2 .gauche").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_g.jpg) no-repeat #FFFFFF"});
		$("#push2 .droite").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_d.jpg) no-repeat #FFFFFF"});	
		$("#push2 .milieu").css ({"margin-top" : "-11px", "border-top" : "5px solid #ef862d"});		
});

$("#push3").mouseenter(
	function () {
		$("#push3 .gauche").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_g.jpg) no-repeat #FFFFFF", "height" : "262px"});
		$("#push3 .droite").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_d.jpg) no-repeat #FFFFFF", "height" : "262px"});
		$("#push3 .milieu").css ({"margin-top" : "-11px", "border-top" : "5px solid #ef862d" });
		$("#push2 .gauche").css ({"width" : "0px"});
		$("#push2 .droite").css ({"width" : "0px"});
		$("#push2 .milieu").css ({"margin-top" : "0px", "border-top" : "0px solid #ef862d"});
	}).mouseleave(function() {
		$("#push3 .gauche").css ({"width" : "0px"});
		$("#push3 .droite").css ({"width" : "0px"});
		$("#push3 .milieu").css ({"margin-top" : "0px", "border-top" : "0px solid #ef862d"});
		$("#push2 .gauche").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_g.jpg) no-repeat #FFFFFF"});
		$("#push2 .droite").css ({"width" : "24px",	"background" : "url(templates/default/images/push_bord_d.jpg) no-repeat #FFFFFF"});
		$("#push2 .milieu").css ({"margin-top" : "-11px", "border-top" : "5px solid #ef862d"	});	
});


//JOBS//


function setupJobs(){
	$('.job', '#contenu').each(
		function(intIndex ){
			
			var job = this;
			//Click sur les Titres
			var titre_btn = $('.wrap_titre', this);
			titre_btn.click(function () { Open(job) } );
			Close(job) ;
			
		});	
}


function Open(i){

	var job = $(i);
	var titre = $('.wrap_titre', job);
	var description = $('.description', job)
	var fleche = $('.fleche', titre);
	
	//Arrive description
	$('.content', description).stop().animate({'opacity': '1'}, 1000);
	$height = $('.content', description).height();
	$(description).stop().animate({'height': $height, 'paddingTop' : '40px', 'marginBottom' : '40px'}, 100);
	
	//Switch fleche
	$('img', fleche).stop().animate({'top': '-2px'}, 800);
	
	//Animaet windows
	$('html, body').stop().animate({scrollTop:  $('#contenu').offset().top }, 1500, 'easeOutExpo');
	
	//Close Others
	$('.job').not(job).each(function(){Close(this)});	
	
	//Change Click to Close
	titre.unbind('click');
	titre.click(function () { 
		Close(job) 		
		$('html, body').stop().animate({scrollTop: 135 }, 1500, 'easeOutExpo');
	});
	
	
}

function Close(item){

	var job = $(item);
	var titre = $('.wrap_titre', job);
	var description = $('.description', job)
	var fleche = $('.fleche', titre);
		
	//Close description
	$('.content', description).stop().animate({'opacity': '0'}, 1000);
	$(description).stop().animate({'height': '0px', 'paddingTop' : '0px', 'marginBottom' : '0px'}, 200, 'easeOutQuad');
	
	//Switch fleche
	$('img', fleche).stop().animate({'top': '-44px'}, 800);
	
	titre.unbind('click');
	titre.click(function () { Open(job) } );
	
}


// OFFRES SLIDESHOW //
  
 function setupOffresCarriere(){
 
	var OffresConteneur = $('.offres');
	var Offres = $('.offre', OffresConteneur);
	var Visuels = $('.visuel', '.bloc_content')
	var nbrOffres = Offres.length;
	var lastOffre;
	var currentOffre;
	var lastVisuel;
	var currentVisuel;
	var i = 1;
	
	//Hide All
	
		$(Visuels).each(
			function(intIndex ){
				
				$(this).css({'display' : 'none'});			
			});	
			
		$(Offres).each(
			function(intIndex ){
				
				$(this).css({'display' : 'none'});			
			});	
			
	
	//Show First
	
		$(Visuels.eq(0)).fadeIn(3000).css({'bottom' : '0'});
		$(Offres.eq(0)).css({'opacity' : '1'}).fadeIn(3000);
	
		
	//Slide 
	
	setInterval(function() {
	
		// set CurrentAndLast
		if (i == 0 ) { 
			lastOffre = $(Offres.eq( nbrOffres - 1 ));
			lastVisuel = $(Visuels.eq( nbrOffres - 1 ));
		}
		else { 
			lastOffre = $(Offres.eq(i-1));
			lastVisuel = $(Visuels.eq(i-1));
		}
				
		currentOffre = $(Offres.eq(i));
		currentVisuel = $(Visuels.eq(i));
				
		//Anim Last
		$(lastOffre).animate ({'marginLeft' : '100px', 'opacity' : '0'}, 1000, function(){$(this).css({'display' : 'none'})});
		$(lastVisuel).fadeOut(1000);
		
		//Anim Current
		$(currentOffre).delay(1000).css({'marginLeft' : '0px', 'opacity' : '1'}).fadeIn(1000);
		$(currentVisuel).css({'bottom' : '0'}).delay(1000).fadeIn(3000);
				
		if ( i < nbrOffres - 1 ){ i++; } 
		else  { i = 0; };
		
   }, 8000);
   
   
}

 function setupOffresHome(){
 
	var OffresConteneur = $('.bloc_content', '.home');
	var Offres = $('.offre', OffresConteneur);
	var Visuels = $('.visuel', '.home')
	var nbrOffres = Offres.length;
	var lastOffre;
	var currentOffre;
	var lastVisuel;
	var currentVisuel;
	var i = 1;
	
	
	//Hide All
	
		$(Visuels).each(
			function(intIndex ){
				
				$(this).css({'display' : 'none'});			
			});	
			
		$(Offres).each(
			function(intIndex ){
				
				$(this).css({'display' : 'none'});			
			});	
	


		//Show First
	
		$(Visuels.eq(0)).css({'top' : '0'}).fadeIn(3000);
		$(Offres.eq(0)).css({'opacity' : '1'}).fadeIn(3000);

		
	setInterval(function() {
	
		// set CurrentAndLast
		if (i == 0 ) { 
			lastOffre = $(Offres.eq( nbrOffres - 1 ));
			lastVisuel = $(Visuels.eq( nbrOffres - 1 ));
		}
		else { 
			lastOffre = $(Offres.eq(i-1));
			lastVisuel = $(Visuels.eq(i-1));
		}
				
		currentOffre = $(Offres.eq(i));
		currentVisuel = $(Visuels.eq(i));
				
		//Anim Last
		$(lastOffre).animate ({'opacity' : '0'}, 1000, function(){$(this).css({'display' : 'none'})});
		$(lastVisuel).fadeOut(1000);
		
		
		//Anim Current
		$(currentOffre).delay(1000).css({'opacity' : '1'}).fadeIn(1000);
		$(currentVisuel).css({'top' : '0'}).delay(1000).fadeIn(3000);
				
		if ( i < nbrOffres - 1 ){ i++; } 
		else  { i = 0; };
		
   }, 12000);
   
}




