var etat=0; 
// 0 : aucune action en cours.
// 1 : prechargement d'une image.
// 2 : affichage de l'image.

function OuvreImage(chemin)
{
	etat=1;
	
	//Mise en mémoire cache du loader.
	loader = new Image(); loader.src="images/ajax-loader.gif";
		
	//Préchargement de l'image dans le buffer
	document.getElementById("buffer").innerHTML="<img src='"+chemin+"' onload=\"affiche('"+chemin+"')\" />";

	// Initialisation des variables
	var cache = document.getElementById("cache").style;
	var ecran = document.getElementById("ecran").style;



	
	//Affichage du chargement
	document.getElementById("ecran").innerHTML="<img src='"+loader.src+"' style='margin-bottom:5px;' /><br />Chargement ...";
	ecran.width="150px";
	ecran.height="60px";
	ecran.top=parseInt(document.documentElement.scrollTop) + 10 + "px";
	ecran.left=((parseInt(document.body.clientWidth +16) - parseInt(ecran.width)) / 2) + "px";
	ecran.display="block";
	
	return false;

}












function affiche(chemin)
{
if(etat == 1)
{
	//Initialisation des variables.
	var ecran = document.getElementById("ecran").style;
	var cache = document.getElementById("cache").style;
	image=new Image(); image.src=chemin;
	taille="";
	etat=2;
	
	// On dimensionne le cache.
	//____________________________________________________________________
	cache.width=document.body.clientWidth +16+ "px";
	
	if(document.body.clientHeight > document.body.offsetHeight)
		cache.height=document.body.clientHeight+"px";
	else
		cache.height=document.body.offsetHeight+"px";

	if(image.height > parseInt(cache.height))
		cache.height = image.height + 16 + "px";
	//____________________________________________________________________
	
	cache.display="block"; // On l'affiche.

	
	//Si l'image dépasse le navigateur
	if(image.width > parseInt(cache.width))
	{
		larg = parseInt(cache.width) - 100;
		haut=parseInt(image.height * larg / image.width);
		taille="style='width:"+larg+"px;height:"+haut+"px;'";
	}
	else
	{
		haut=image.height;
		larg=image.width;
	}

	//On affiche l'image
	document.getElementById("ecran").innerHTML="<img src='"+image.src+"' "+taille+" />";
	ecran.left=((parseInt(cache.width) - larg) / 2) + "px";
	ecran.display="block";
	
	//Lancement de l'animation d'ouverture d'image.
	ecran.height="0px";
	hauteur=setInterval("ch_haut("+haut+")", 20);
	ecran.width="0px";
	largeur=setInterval("ch_larg("+larg+")", 20);
	
}
}















//Animation
function ch_haut(fin)
{
	i=parseInt(document.getElementById("ecran").style.height) + 50;
	if(i > fin)
	{
		i=fin;
		clearInterval(hauteur);
	}
	document.getElementById("ecran").style.height=i + "px";
}

function ch_larg(fin)
{
	i=parseInt(document.getElementById("ecran").style.width) + 50;
	if(i > fin)
	{
		i=fin;
		clearInterval(largeur);
	}
	document.getElementById("ecran").style.width=i + "px";
}









function ferme()
{
	document.getElementById("ecran").style.display="none";
	document.getElementById("cache").style.display="none";
	document.getElementById("buffer").innerHTML="";
	etat=0;
	
}



function getEcran()
{
	return '<div id="buffer" style="display:none;"></div><div id="ecran" style="background:#DDDDEE;position:absolute;z-index:2;display:none;border:3px solid black;text-align:center;padding:0;overflow:hidden;cursor:hand;cursor:pointer;margin:0;" title="Fermer" onclick="ferme()"></div><div id="cache" style="background:black;position:absolute;top:0;left:0;display:none;opacity:0.7;z-index:1;filter : alpha(opacity=70);"> </div>';
}