
var repAutomoteur = "images/";  // Répertoire des images du diaporama (vide si meme repertoire que le fichier html)
var numAutomoteur = 0;
var myCounterAutomoteur;
var next_imgAutomoteur = new Image;
next_imgAutomoteur.src = repAutomoteur+"pixel_transparent.gif"; 
var wPopupAutomoteur;
var tabImgAutomoteur;
var tabImgSaveAutomoteur;
var nb_imgAutomoteur;
var pauseAutomoteur = 5000;

tabImgSaveAutomoteur = new Array(1);

tabImgSaveAutomoteur[0] = 'Barber.JPG';
nb_imgAutomoteur = tabImgSaveAutomoteur.length;
	       
function nextAutomoteur() {
	//setTimeout("other()",1000)
	// Est-ce que l'image suivante est réchargée ?
if(wPopupAutomoteur){
	if(next_imgAutomoteur.complete) {
		// Oui, alors après le temps de pauseAutomoteur choisi par l'utilisateur, cette image remplacera l'actuelle
		launchAgainAutomoteur();
	}
	else {
		// Non, alors on continue d'attendre qu'elle le soit
		setTimeout("nextAutomoteur()", 100);
	}
 }
}

// Lance le slideshow
function launchAutomoteur() {
	// Petite vérification de la temporisation choisie
	
	// Ordre normal ou aléatoire
	numAutomoteur = 0;
	tabImgAutomoteur = tabImgSaveAutomoteur;
	
	// Avant de lancer le slideshow, on désactive tous les éléments du formulaire
	// et on active le bouton "Stopper"
	next_imgAutomoteur.src = repAutomoteur+tabImgAutomoteur[0];
	//focusOnStop();
	
	wPopupAutomoteur = window.open('', 'img_popup', 'width=50, height=50, top='+(screen.height-50)/2+', left='+(screen.width-50)/2+', status=no, directories=no, toolbar=no, location=no, menubar=no, scrollbars=no, resizable=yes');

	launchAgainAutomoteur();
}

// Poursuit le slideshow
function launchAgainAutomoteur() {
	// Si la fenêtre n'existe pas ou est fermée, on la réouvre
	//if(!wPopupAutomoteur) {
	//	wPopupAutomoteur = window.open('', 'img_popup', 'width=50, height=50, top='+(screen.height-50)/2+', left='+(screen.width-50)/2+', status=no, directories=no, toolbar=no, location=no, menubar=no, scrollbars=no, resizable=yes');
	//}
	
	if(wPopupAutomoteur){
	// On écrit le contenu de la fenêtre popup
	wPopupAutomoteur.document.clear();
	wPopupAutomoteur.document.write("<HTML><HEAD><TITLE>Automoteur : "+(numAutomoteur+1)+"/"+nb_imgAutomoteur+"</TITLE></HEAD>");

	// La fonction qui attend que l'image soit chargée et affichée pour redimensionner la fenêtre à la bonne taille
	wPopupAutomoteur.document.write('<SCRIPT language="JavaScript">\nfunction checkSize() { if(document.images && document.images[0].complete) { w = document.images[0].width+50; h = document.images[0].height+100; window.resizeTo(w, h); window.moveTo((screen.width-w)/2, (screen.height-h)/2); document.images[0].style.visibility = "visible"; window.focus(); if(opener.next_imgAutomoteur.src != opener.repAutomoteur+opener.tabImgAutomoteur[opener.numAutomoteur]) { opener.next_imgAutomoteur.src = opener.repAutomoteur+opener.tabImgAutomoteur[opener.numAutomoteur]; } } else { setTimeout("checkSize()", 250); } }\n</'+'SCRIPT>');
	
	wPopupAutomoteur.document.write('<BODY bgcolor="#FFFFFF" leftMargin="0" topMargin="0" marginWidth="0" marginHeight="0">');
	wPopupAutomoteur.document.write('<table width="100%" height="100%" align="center" cellpadding="0" cellspacing="0"><tr valign="middle"><td align="center"><img src="'+next_imgAutomoteur.src+'" border="2" onLoad="checkSize()"  onClick="window.opener.otherAutomoteur()" style="visibility:hidden"></td></tr><tr valign="center=><td><a href="javascript:onClick=window.opener.otherAutomoteur();"></a></td></tr></table>');
	//wPopupAutomoteur.document.write('<div align="center"> <h1>Tout centré</h1> </div>');

	wPopupAutomoteur.document.write('</BODY></HTML>');
	wPopupAutomoteur.document.close();
	numAutomoteur++;
	
	
	// Si "Répéter" n'est pas cochée, on stoppe le slideshow
	if(numAutomoteur == nb_imgAutomoteur) {
		setTimeout("stopAutomoteur()", pauseAutomoteur);
		return false;
	}
	

	myCounterAutomoteur=setTimeout("nextAutomoteur()",pauseAutomoteur);
	}else{
	clearTimeout(myCounterAutomoteur);
	numAutomoteur = 0;
	}
}

// Stoppe le slideshow
function stopAutomoteur() {
	clearTimeout(myCounterAutomoteur);
	wPopupAutomoteur.close();	
	// On réactive tous les éléments du formulaire
	// et on désactive le bouton "Stopper"
	//focusOnLaunch();
	
	numAutomoteur = 0;
}

function otherAutomoteur() {
	if(numAutomoteur!=nb_imgAutomoteur){
	clearTimeout(myCounterAutomoteur);
	nextAutomoteur();
	}else{
	stopAutomoteur();
	}	
}


