var tab_image = [];
var tab_id = [];
var cpt_image = 0;
var cpt_global = 0;

var ximg = 0;
var wimg = 0;
var http;

function majtab(id_dossier)
{
	tab = new Array();
	cpt = 0;
	temp = new Array();
	tab_image = new Array();
	tab_id = new Array();
	cpt_image = 0;
	
	new Ajax.Request("action_diapo.php?id_dossier=" + id_dossier + "&cas=1", {
		onSuccess: function(transport) {
			/* On separe les photos et on obtient un 
			  *tableau de couples "chemin de la photo ;; id_photo" */
			tab = transport.responseText.split("!!");
			cpt = tab.length;
			for(var i=0;i<cpt;i++) {
				/* on sépare les id des photos et les chemins des images */
				temp = tab[i].split(";;");
				tab_image[cpt_image] = temp[0];
				tab_id[cpt_image] = temp[1];
				cpt_image++;
			}
			aff_diapo(0);
		}
	});
}

function getInfosPhotos(id)
{
	new Ajax.Request("action_diapo.php?id_dossier=" + id + "&cas=2", {
		onSuccess: function(transport) {
			results = transport.responseText.split("!!;;");
			results2 = results[1].split("!;!;");
			
			ximg = results2[0];
			wimg = results2[1];
			
			findObj("Infos_photo").innerHTML = results[0];
			setImage(ximg,wimg,results2[2]);
		}
	});
}

function setImage(w,h,nom)
{
	document.getElementById("backDiv").style.display="";
	document.body.style.overflow="hidden";

	var oImg = null;
	
	if(fili==1)
	{			
		if(document.getElementById("Layer1"))
		{
			
			if(w > h)
			{
				var hgt_temp = w-h;
				var hgt = h;
			} else {
				var hgt = h;	
			}
			
			document.getElementById("ImgCourante").style.width = w+"px";
			document.getElementById("ImgCourante").style.height = hgt+"px";					
			document.getElementById("Layer1").style.width = w+"px";
			document.getElementById("Layer1").style.height = h+"px";
			document.getElementById("Layer1").style.background="url('"+nom+"') no-repeat";
		}
	}
	else
		document.getElementById("ImgCourante").src=nom;		
	document.getElementById("diapo").style.display="";
}

var x = null;

function aff_diapo(cpt)
{
	cpt_global = cpt;
	if(cpt>=cpt_image)
	{
		cpt = 0;
	}
	if(cpt <= cpt_image)
	{
		getInfosPhotos(tab_id[cpt]);
	}
	if(x!=null)
		clearTimeout(x);
	cpt++;
	x = setTimeout("aff_diapo("+cpt+")",5000);
}

function action_dipo(action)
{
	if(action == 1)
	{ /* arreter */
		if(x!=null)
			clearTimeout(x);
		x=null;
	}
	else if(action == 2)
	{ /* demarrer */
		aff_diapo(0);
	}
	else if(action == 3)
	{ /* image suivante */
		aff_diapo(cpt_global+1);
	}
	else if(action == 4)
	{ /* image precedente */
		var cpt = cpt_global-1;
		if(cpt < 0)
			cpt = 0;
		aff_diapo(cpt);
	}
	else if(action == 5)
	{ /* fermeture du diaporama */
		if(x!=null)
			clearTimeout(x);
		x=null;
		document.getElementById("backDiv").style.display="none";
		document.getElementById("diapo").style.display="none";
		document.body.style.overflow="";
	}
}

