
var repCamions = "images/";  // Répertoire des images du diaporama (vide si meme repertoire que le fichier html)
var numCamions = 0;
var myCounterCamions;
var next_imgCamions = new Image;
next_imgCamions.src = repCamions+"pixel_transparent.gif"; 
var wPopupCamions;
var tabImgCamions;
var tabImgSaveCamions;
var nb_imgCamions;
var pauseCamions = 5000;

tabImgSaveCamions = new Array(3);

tabImgSaveCamions[0] = 'CamionTribenne.JPG';
tabImgSaveCamions[1] = 'CamionPorteEngin.JPG';
tabImgSaveCamions[2] = 'CamionGrue.JPG';
nb_imgCamions = tabImgSaveCamions.length;
	       
function nextCamions() {
	//setTimeout("other()",1000)
	// Est-ce que l'image suivante est réchargée ?
if(wPopupCamions){
	if(next_imgCamions.complete) {
		// Oui, alors après le temps de pauseCamions choisi par l'utilisateur, cette image remplacera l'actuelle
		launchAgainCamions();
	}
	else {
		// Non, alors on continue d'attendre qu'elle le soit
		setTimeout("nextCamions()", 100);
	}
 }
}

// Lance le slideshow
function launchCamions() {
	// Petite vérification de la temporisation choisie
	
	// Ordre normal ou aléatoire
	numCamions = 0;
	tabImgCamions = tabImgSaveCamions;
	
	// Avant de lancer le slideshow, on désactive tous les éléments du formulaire
	// et on active le bouton "Stopper"
	next_imgCamions.src = repCamions+tabImgCamions[0];
	//focusOnStop();
	
	wPopupCamions = 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');

	launchAgainCamions();
}

// Poursuit le slideshow
function launchAgainCamions() {
	// Si la fenêtre n'existe pas ou est fermée, on la réouvre
	//if(!wPopupCamions) {
	//	wPopupCamions = 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(wPopupCamions){
	// On écrit le contenu de la fenêtre popup
	wPopupCamions.document.clear();
	wPopupCamions.document.write("<HTML><HEAD><TITLE>Camions : "+(numCamions+1)+"/"+nb_imgCamions+"</TITLE></HEAD>");

	// La fonction qui attend que l'image soit chargée et affichée pour redimensionner la fenêtre à la bonne taille
	wPopupCamions.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_imgCamions.src != opener.repCamions+opener.tabImgCamions[opener.numCamions]) { opener.next_imgCamions.src = opener.repCamions+opener.tabImgCamions[opener.numCamions]; } } else { setTimeout("checkSize()", 250); } }\n</'+'SCRIPT>');
	
	wPopupCamions.document.write('<BODY bgcolor="#FFFFFF" leftMargin="0" topMargin="0" marginWidth="0" marginHeight="0">');
	wPopupCamions.document.write('<table width="100%" height="100%" align="center" cellpadding="0" cellspacing="0"><tr valign="middle"><td align="center"><img src="'+next_imgCamions.src+'" border="2" onLoad="checkSize()"  onClick="window.opener.otherCamions()" style="visibility:hidden"></td></tr><tr valign="center=><td><a href="javascript:onClick=window.opener.otherCamions();"></a></td></tr></table>');
	//wPopupCamions.document.write('<div align="center"> <h1>Tout centré</h1> </div>');

	wPopupCamions.document.write('</BODY></HTML>');
	wPopupCamions.document.close();
	numCamions++;
	
	
	// Si "Répéter" n'est pas cochée, on stoppe le slideshow
	if(numCamions == nb_imgCamions) {
		setTimeout("stopCamions()", pauseCamions);
		return false;
	}
	

	myCounterCamions=setTimeout("nextCamions()",pauseCamions);
	}else{
	clearTimeout(myCounterCamions);
	numCamions = 0;
	}
}

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

function otherCamions() {
	if(numCamions!=nb_imgCamions){
	clearTimeout(myCounterCamions);
	nextCamions();
	}else{
	stopCamions();
	}	
}


