var xhr = null;
var objTimerPicture=null;

function getXhr(){
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
	}
	else { // XMLHttpRequest non supporté par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
}

/**
* Méthode qui sera appelée sur le click du bouton
*/


function detailimage(ObjImage,id,media){
	
	getXhr()	
	// On défini ce qu'on va faire quand on aura la réponse
	//alert (xhr.onreadystatechange);
	xhr.onreadystatechange = function(){
		//alert ("test4passé");
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 ){
			//alert (xhr.status);
			if (xhr.status == 200){
				//alert ("test2passé");
				if (ObjImage)
				{
					if (media=='MediaImage'){
					x=getOffsetPosition(ObjImage,'Left')+60;
					y=getOffsetPosition(ObjImage,'Top')+(-43);
					}
					else {
					x=getOffsetPosition(ObjImage,'Left')-85;
					y=getOffsetPosition(ObjImage,'Top')+(-43);
					}
					x2=x;			
					if (x+250>document.body.clientWidth){	x=document.body.clientWidth-290; }
					//alert (document.body.clientWidth);
					//document.getElementById("Debug").style.display = 'block';
					//document.getElementById("Debug").innerHTML="x = "+x2+" lagueur fenetre= "+document.body.clientWidth;
						//if (x>document.body.clientWidth/2){	x-=400;}
					//alert (x);
					objHTML=document.getElementById("infosimage");
					if (objHTML==null)
						{
						div=document.createElement("div");
						div.className='infosimage';
						div.style.position='absolute';
						div.style.display='none';
						div.id='infosimage';
						div.onmouseover=function()	{ OverPicture(); }  
						div.onmouseout=function()	{ cachedetailimage(); }  
						div.innerHTML="<div class=\"Separation\">&nbsp;</div>";
						document.body.appendChild(div);
						}

					document.getElementById("infosimage").innerHTML = xhr.responseText;
					document.getElementById("infosimage").style.left = x + 'px';
					document.getElementById("infosimage").style.top = y + 'px';
					document.getElementById("infosimage").style.display = 'block';

				}
			}
		}
	}
	xhr.open("GET","javascript/contenuAjax.php?NumFichier=" + id + "",true);
	xhr.send(null);

}


function cachedetailimage (){
OverPicture();
objTimerPicture=setInterval('ClosePicture()',100)

}

function ClosePicture()
{
OverPicture();
obj=document.getElementById("infosimage");
if (obj) obj.style.display='none';
}

function OverPicture(){
	if (objTimerPicture)	clearInterval(objTimerPicture);
}

