// initialisation des images
// image1 pour Col1
// image2 pour Col2
// image3 pour Col3
var ImgIdxCol = new Array();
ImgIdxCol[1] = 1;
ImgIdxCol[2] = 4;
ImgIdxCol[3] = 7;

//alert("test "+$("#Sec").attr("src"));
$("#imgCol1").ImageSwitch({	Type:"ScrollIn", 
						NewImage:"images/2010/diapo/photo"+ImgIdxCol[1]+".jpg",
						Direction: "TopDown",
						StartOpacity: 1,
						Speed: 1000
						});
$.ajax({
   type: "POST",
   url: "getLegende.php",
   data: "data="+ImgIdxCol[1],
   success: function(msg){
     //alert( "Data Saved: " + msg );
		document.getElementById("legCol1").innerHTML = msg;
   }
});

//alert("test "+$("#Sec").attr("src"));
$("#imgCol2").ImageSwitch({	Type:"ScrollIn", 
						NewImage:"images/2010/diapo/photo"+ImgIdxCol[2]+".jpg",
						Direction: "TopDown",
						StartOpacity: 1,
						Speed: 1000
						});
$.ajax({
   type: "POST",
   url: "getLegende.php",
   data: "data="+ImgIdxCol[2],
   success: function(msg){
     //alert( "Data Saved: " + msg );
		document.getElementById("legCol2").innerHTML = msg;
   }
});


//alert("test "+$("#Sec").attr("src"));
$("#imgCol3").ImageSwitch({	Type:"ScrollIn", 
						NewImage:"images/2010/diapo/photo"+ImgIdxCol[3]+".jpg",
						Direction: "TopDown",
						StartOpacity: 1,
						Speed: 1000
						});
$.ajax({
   type: "POST",
   url: "getLegende.php",
   data: "data="+ImgIdxCol[3],
   success: function(msg){
     //alert( "Data Saved: " + msg );
		document.getElementById("legCol3").innerHTML = msg;
   }
});



var maxFile = 0;

var OpenDate = new Date();

$.ajax({
	   type: "POST",
	   url: "countFile.php",
	   success: function(msg){
			maxFile = msg;
	   }
	});

var DrawClock = function(){
	
	var CurrentDate = new Date();

	
	$timePassed = Math.round((CurrentDate - OpenDate)/1000);
	
	if ($timePassed >= 5){

		switch (($timePassed % 9)){
			case 5 :
				ImgIdxCol[1] ++;
				if (ImgIdxCol[1] > maxFile){
					ImgIdxCol[1] = 1;
				}
				//alert('modif de ImgIdxCol[1] : '+ImgIdxCol[1]);
				break;
			case 8 :
				ImgIdxCol[2] ++;
				if (ImgIdxCol[2] > maxFile){
					ImgIdxCol[2] = 1;
				}
				//alert('modif de ImgIdxCol[2] : '+ImgIdxCol[2]);
				break;
			case 2 :
				ImgIdxCol[3] ++;
				if (ImgIdxCol[3] > maxFile){
					ImgIdxCol[3] = 1;
				}
				//alert('modif de ImgIdxCol[3] : '+ImgIdxCol[3]);
				break;
			default:break;
		}
		
		//alert("test "+ImgIdxCol[1]);
		
		if($("#imgCol1").attr("src") != "images/2010/diapo/photo"+ImgIdxCol[1]+".jpg")
		{
			//alert("test "+$("#Sec").attr("src"));
			$("#imgCol1").ImageSwitch({	Type:"ScrollIn", 
									NewImage:"images/2010/diapo/photo"+ImgIdxCol[1]+".jpg",
									Direction: "TopDown",
									StartOpacity: 1,
									Speed: 1000
									});
			$.ajax({
			   type: "POST",
			   url: "getLegende.php",
			   data: "data="+ImgIdxCol[1],
			   success: function(msg){
			     //alert( "Data Saved: " + msg );
					document.getElementById("legCol1").innerHTML = msg;
			   }
			});
			
			
		}
		
		if($("#imgCol2").attr("src") != "images/2010/diapo/photo"+ImgIdxCol[2]+".jpg")
		{
			//alert("test "+$("#Sec").attr("src"));
			$("#imgCol2").ImageSwitch({	Type:"ScrollIn", 
									NewImage:"images/2010/diapo/photo"+ImgIdxCol[2]+".jpg",
									Direction: "TopDown",
									StartOpacity: 1,
									Speed: 1000
									});
			
			$.ajax({
			   type: "POST",
			   url: "getLegende.php",
			   data: "data="+ImgIdxCol[2],
			   success: function(msg){
				document.getElementById("legCol2").innerHTML = msg;
			   }
			});
		}
		
		if($("#imgCol3").attr("src") != "images/2010/diapo/photo"+ImgIdxCol[3]+".jpg")
		{
			//alert("test "+$("#Sec").attr("src"));
			$("#imgCol3").ImageSwitch({	Type:"ScrollIn", 
									NewImage:"images/2010/diapo/photo"+ImgIdxCol[3]+".jpg",
									Direction: "TopDown",
									StartOpacity: 1,
									Speed: 1000
									});
			
			$.ajax({
			   type: "POST",
			   url: "getLegende.php",
			   data: "data="+ImgIdxCol[3],
			   success: function(msg){
				document.getElementById("legCol3").innerHTML = msg;
			   }
			});
		}
	
	}
	
}





$(document).ready(function(){
		
	setInterval(DrawClock,1000);
	
	$("div#row1 > div").hover( function(){
			if ($(this).children("div.legende").html() != ''){
			$(this).children("div.legende").show();
		}
	},function(){
		$(this).children("div.legende").hide();
	})
	
	
});



