var homeactif = 1;
var GLOBAL_T = false;
var GLOBAL_T2 = false;
var GLOBAL_CONTINU = true;
var photocourante = 1;
var nbphotocadre1 = 1;
var nbphotocadre2 = 1;
var nbphotocadre3 = 5;
var nbphotocadre4 = 1;
var nbphotocadre5 = 4;

function changerphotocourante(elemid){
			if(elemid == homeactif){
			  clearTimeout(GLOBAL_T2);
			  GLOBAL_T2 = false;
			  photocourante++;
			  switch(eval(elemid)){
			  	case 1 : 
			  		if(photocourante == nbphotocadre1)
			  			photocourante = 1;
			  	break;	
			  	case 2 : 
			  		if(photocourante == nbphotocadre2)
			  			photocourante = 1;			  	
			  	break;	
			  	case 3 : 
			  		if(photocourante == nbphotocadre3)
			  			photocourante = 1;			  	
			  	break;	
			  	case 4 : 
			  		if(photocourante == nbphotocadre4)
			  			photocourante = 1;			  	
			  	break;	
			  	case 5 : 
			  		if(photocourante == nbphotocadre5)
			  			photocourante = 1;			  	
			  	break;	  	
			  }
			$('#homecadre_'+elemid).fadeOut(function(){
				$('#homecadre_1').attr('class', 'cadrecol1 homecadrephoto1_1');
				$('#homecadre_2').attr('class', 'cadrecol1 homecadrephoto2_1');
				$('#homecadre_3').attr('class', 'cadrecol1 homecadrephoto3_1');
				$('#homecadre_4').attr('class', 'cadrecol1 homecadrephoto4_1');
				$('#homecadre_5').attr('class', 'cadrecol1 homecadrephoto5_1');
				$('#homecadre_'+elemid).attr('class', 'cadrecol1 homecadrephoto'+elemid+'_'+photocourante);
				$('#homecadre_'+elemid).fadeIn();
			});	
			if(GLOBAL_CONTINU){
				switch(eval(elemid)){
					case 1 :
						if(photocourante < nbphotocadre1)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);
					break; 	
					case 2 :
						if(photocourante < nbphotocadre2)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);				
					break; 	
					case 3 :
						if(photocourante < nbphotocadre3)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);				
					break; 	
					case 4 :
						if(photocourante < nbphotocadre4)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);				
					break; 	
					case 5 :
						if(photocourante < nbphotocadre5)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);		
					break; 	
				}
			}
			else {
				switch(eval(elemid)){
					case 1 :
						if(photocourante == nbphotocadre1)
							photocourante = 0;
						if(nbphotocadre1 > 1)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);
					break; 	
					case 2 :
						if(photocourante == nbphotocadre2)
							photocourante = 0;	
						if(nbphotocadre2 > 1)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);			
					break; 	
					case 3 :
						if(photocourante == nbphotocadre3)
							photocourante = 0;	
						if(nbphotocadre3 > 1)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);			
					break; 	
					case 4 :
						if(photocourante == nbphotocadre4)
							photocourante = 0;	
						if(nbphotocadre4 > 1)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);			
					break; 	
					case 5 :
						if(photocourante == nbphotocadre5)
							photocourante = 0;	
						if(nbphotocadre5 > 1)
							GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);			
					break; 	
				}
							
			}
			}
}

function homeimage(elemid, continuseul){
		if(elemid == 6)
			elemid = 1;
		$(".cadreboxtext").removeClass("active");
		$("#home_"+elemid).addClass("active");
		//$(".cadrecol1").hide("fast");
		if(homeactif == elemid){ $("#homecadre_"+elemid).show(); }
		else if(homeactif < elemid){
			$("#homecadre_"+homeactif).stop(true, true).show();
			$("#homecadre_"+elemid).show("slow", function(){
				$(".cadrecol1").addClass('cache');
				$("#homecadre_"+elemid).removeClass('cache');
				$('.cache').hide('slow');			
			});
			$("#homecadre_"+elemid).show();
		}
		else {
				$("#homecadre_"+elemid).stop(true, true).show();
				$("#homecadre_"+homeactif).stop(true, true).hide("slow", function(){
					$(".cadrecol1").addClass('cache');
					$("#homecadre_"+elemid).removeClass('cache');
					$('.cache').hide();	
				});
			$("#homecadre_"+elemid).show();
		}
		
			switch(eval(elemid)){
				case 1 :
					if(nbphotocadre1 > 1)
						GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);
					
				break; 	
				case 2 :
					if(nbphotocadre2 > 1)
						GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);				
				break; 	
				case 3 :
					if(nbphotocadre3 > 1)
						GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);				
				break; 	
				case 4 :
					if(nbphotocadre4 > 1)
						GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);				
				break; 	
				case 5 :
					if(nbphotocadre5 > 1)
						GLOBAL_T2 = setTimeout("changerphotocourante("+elemid+")", 4000);				
				break; 	
			}
		
		$("#homecadre_"+elemid).show();
		homeactif = elemid;
		if(continuseul == 0 && GLOBAL_CONTINU){
			switch(eval(elemid)){
				case 1 :
						GLOBAL_T = setTimeout("homeimage(2, 0)",4000);
				break; 	
				case 2 :
						GLOBAL_T = setTimeout("homeimage(3, 0)", (nbphotocadre2 * 4000));		
				break; 	
				case 3 :
						GLOBAL_T = setTimeout("homeimage(4, 0)", (nbphotocadre3 * 4000));		
				break; 	
				case 4 :
						GLOBAL_T = setTimeout("homeimage(5, 0)", (nbphotocadre4 * 4000));		
				break; 	
				case 5 :
						GLOBAL_T = setTimeout("homeimage(1, 0)", (nbphotocadre5 * 4000));			
				break; 	
			}
		}
		else {
			  clearTimeout(GLOBAL_T);
			  GLOBAL_T = false;
			  GLOBAL_CONTINU = false;
				
		}
			
		return false;
	
}


$(document).ready(function(){
	$("#menu2 ul li").mouseover(function(){
		$(this).children("ul").stop(true, true).show();
	});
	
	$("#menu2 ul li").mouseout(function(elem){
		elem = $(this).children("ul");
		elem.stop(true, true).delay(100).hide(200); 
	});




	$(".cadreboxtext").click(function(){
		var continuseul = 1;
		photocourante = 1;
		var rechercheid = $(this).attr('id').split('_');
		elemid = rechercheid[1];
		$('#homecadre_1').attr('class', 'cadrecol1 homecadrephoto1_1');
		$('#homecadre_2').attr('class', 'cadrecol1 homecadrephoto2_1');
		$('#homecadre_3').attr('class', 'cadrecol1 homecadrephoto3_1');
		$('#homecadre_4').attr('class', 'cadrecol1 homecadrephoto4_1');
		$('#homecadre_5').attr('class', 'cadrecol1 homecadrephoto5_1');
		$('#homecadre_'+elemid).attr('class', 'cadrecol1 homecadrephoto'+elemid+'_1');
		homeimage(elemid, continuseul);
		return false;
	});
	
	homeimage(1, 0);
	
});

