var classImg;

function wait(){
	document.getElementById("imgRealisation").src = "./templates/images/chargement.gif";
	document.getElementById("imgRealisation").style.height = '30px';
	document.getElementById("imgRealisation").style.width = '30px';
	document.getElementById("imgRealisation").style.border = '0px';
	document.getElementById("imgRealisation").style.marginLeft = '220px';
	document.getElementById("imgRealisation").style.marginTop = '120px';
	document.getElementById("imgRealisation").style.marginBottom = '120px';
}
function unWait(){
	var color = '#90400b';
	if (classImg == "violet") { color = '#90400b'; }
	else if (classImg == "orange") { color = '#90400b'; }
	else if (classImg == "rose") { color = '#90400b'; }
	else if (classImg == "jaune") { color = '#90400b'; }
	else if (classImg == "bleu") { color = '#90400b'; }
	else if (classImg == "vert") { color = '#90400b'; }
	document.getElementById("imgRealisation").style.border = 'solid 1px ' + color;
	document.getElementById("imgRealisation").style.marginLeft = '0px';
	document.getElementById("imgRealisation").style.marginTop = '5px';
	document.getElementById("imgRealisation").style.marginBottom = '00px';
	document.getElementById("imgRealisation").style.width = '338px';
	document.getElementById("imgRealisation").style.height = '282px';
}
function listeImg(idA){
	classImg = document.getElementById("imgRealisation").className;

	var destination = 'listImg.php?idA=' + idA;
	var donnees = '';
	if(window.XMLHttpRequest){
		xhr_object = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		return(false);
	}
	
	xhr_object.open("POST", destination, true);
	
	xhr_object.onreadystatechange = function() { 
		if(xhr_object.readyState == 1){
			wait();
		}
		if(xhr_object.readyState == 4){
			var retour = xhr_object.responseText;
			retour =  retour.substring(0,(retour.length-1));
			var tableau = retour.split("*");
			variImg(tableau, 0, idA);
		}
	} 
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
	xhr_object.send(donnees); 

}
var timeout1;
var timeout2;

function variImg(obj,lign,idA){
	if(lign == 0){
		obj2 = obj;
		lign2 = lign;
	}
	
	// chargement de l'image
	var image = document.getElementById('imgRealisation');
	//var desc = document.getElementById('texteRealisation');
	img = new Image();
	img.onload=function() {
		image.src= "./images/" + idA + "/"+obj2[lign2];
		unWait();
		//Relance du compteur
		lign2++;
		if(lign2 < obj2.length){ 
			timeout1 = setTimeout("variImg('obj2','lign2', " + idA + ")",4000); 
		}else{
			lign2 = 0;
			timeout2 = setTimeout("variImg('obj2','lign2', " + idA + ")",4000);
		}
		return false;
	}
	img.src= "./images/" + idA + "/"+obj2[lign2];
}

function test (lign, idA) {
	clearTimeout (timeout1);
	clearTimeout (timeout2);
	wait();
	lign2 = lign;
	variImg ('obj2', 'lign2', idA);
}