var idx_diapo=0;
var Nb_diapo=0; // nombre total de diapo pour chaque gîte
var IntervalDiapo=2000; // en millisecondes
var IntervalLegende=500; // en millisecondes
var DureeLegendeON=2000;
var DureeLegende=6000;
var TimeLegende=0;
var diapo=new Array();
var PrefixId = "ecran";
var intervalID;
var intervalID2;
var statusDiapo=true;

function init() {
	Nb_diapo=0;
	var N=document.images.length;
	var re= new RegExp("^ecran");
	for(var i=0;i<N;i++) {
		obj=document.images[i];
		if (re.test(obj.name)) {
			diapo[Nb_diapo]=i;
			Nb_diapo++;
		}		
	}
	document.images[diapo[0]].style.visibility = "visible";
	idx_diapo=0;
	runDiapo();
	
}


function diaporama() {
	document.images[diapo[idx_diapo]].style.visibility = "hidden";
	idx_diapo++;
	idx_diapo = idx_diapo % Nb_diapo;
	document.images[diapo[idx_diapo]].style.visibility = "visible";
}

function endDiapo() {
	clearInterval(intervalID);
	clearInterval(intervalID2);
	document.getElementById("ecran_legende").style.visibility = "hidden";
}

function zooming(fichier) {
	 clearInterval(intervalID);
	 clearInterval(intervalID2);
	document.ImgZoom.src = fichier;
	document.getElementById("zoom").style.zIndex = 100;
	document.getElementById("zoom").style.visibility = "visible";	
}

function runDiapo()
{
	if (statusDiapo==true) 
		intervalID = setInterval("diaporama()",IntervalDiapo);	

}

function endZoom()
{
	document.getElementById("zoom").style.zIndex=0;
	document.getElementById("zoom").style.visibility = "hidden";
}

function PrevDiapo()
{
	document.images[diapo[idx_diapo]].style.visibility = "hidden";	 	
	idx_diapo--;
	if (idx_diapo==-1) idx_diapo = idx_diapo + Nb_diapo;
	document.images[diapo[idx_diapo]].style.visibility = "visible";	
}

function NextDiapo()
{
	document.images[diapo[idx_diapo]].style.visibility = "hidden";
	idx_diapo++;
	idx_diapo = idx_diapo % Nb_diapo;
	document.images[diapo[idx_diapo]].style.visibility = "visible";	
}

StopStartDiapo = function (htmlelement)
{

	if (statusDiapo==true) {
		endDiapo();
		statusDiapo=false;
		htmlelement.src="squelettes/ecran/start.gif";
		
	}
	else {
		statusDiapo=true;
		htmlelement.src="squelettes/ecran/stop.gif";
	}	
		
}


function ZoomDiapo()
{
	document.ImgZoom.src = document.images[diapo[idx_diapo]].src;
	document.getElementById("zoom").style.zIndex = 100;
	document.getElementById("zoom").style.visibility = "visible";	
}

function LegendeDiapo() {
	if (TimeLegende < DureeLegendeON) 
		document.getElementById("ecran_legende").style.visibility = "visible"
	else
		document.getElementById("ecran_legende").style.visibility = "hidden"
		
	TimeLegende = (TimeLegende + IntervalLegende) 
	if (TimeLegende> DureeLegende) {
		TimeLegende = 0;
		DureeLegende += 1000;
	}		
				
}

function runLegende()
{
	intervalID2 = setInterval("LegendeDiapo()",IntervalLegende);	

}

