

//if (typeof BrowserDetect == "undefined")
    document.write("<script src='lightbox/lightbox.js'></script>");

var debug = 0;
var _gar_timer;
var X;
var Y;

document.write('<div id="Myimageid" style="position: absolute;display: none;left: 0px;top: 0px;z-index: 200;"></div>');

function getimageobj()
{
    if (document.getElementById)
        return document.getElementById("Myimageid").style
    else if (document.all)
        return document.all.Myimageid.style
}

function getimageobjnostyle()
{
    if (document.getElementById)
        return document.getElementById("Myimageid")
    else if (document.all)
        return document.all.Myimageid
}

function truebody()
{
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showImage(imagename){

	// ajout perso : mise à jour bd
	var perso_lien = imagename;
	var pos_depart = perso_lien.indexOf('?fichier=');
	var nom_temp = perso_lien.substr(pos_depart + 10);
	var pos_fin = nom_temp.indexOf('/');
	var nom_repertoire = nom_temp.substr(0, pos_fin);
	var nom_image = nom_temp.substr(pos_fin + 1);
	var commentaire_photo = "";

	document.onmousemove=followmouse;
  newHTML = '<div style="padding: 0px; background-color: #ffffff; border: 1px solid #000000;">';
  newHTML = newHTML + "<div align=\"center\" id=\"MyimageComment\" style=\"padding: 2px 0px 2px 0px;\">&nbsp;</div>";
  newHTML = newHTML + '<div align="center" style="padding: 0px 0px 0px 0px;">';
  newHTML = newHTML + '<img src="' + imagename + '" border="0"></div>';
  newHTML = newHTML + '</div>';
	getimageobjnostyle().innerHTML = newHTML;

	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
		  G_obj('MyimageComment').innerHTML = xhr.responseText;
			}
		}
	xhr.open("GET","galerie-photo-comment.php?r="+nom_repertoire+"&p="+nom_image+"",true);
	xhr.send(null);

	var xhr1 = getXhr();
	xhr1.onreadystatechange = function(){}
	xhr1.open("GET","galerie-photo-update.php?r="+nom_repertoire+"&p="+nom_image+"",true);
	xhr1.send(null);
	}

function hideImage(){
	getimageobj().innerHTML = " ";
	getimageobj().display="none"
	document.onmousemove=""
	getimageobj().left="-500px";
	}

function get_position(element){
    var p = {x: element.offsetLeft || 0, y:element.offsetTop || 0};
    while (element = element.offsetParent) {
      p.x += element.offsetLeft;
      p.y += element.offsetTop;
	    }
    if (!p)
        p = {x: element.offsetWidth || 0, y:element.offsetHeight || 0};
    return p;
}

function posmouse(e){
  X = (typeof e != "undefined") ? e.pageX : event.clientX;
  Y = (typeof e != "undefined") ? e.pageY : event.clientY;    
	}

function followmouse(e){
	var xcoord=0
	var ycoord=0
	
	var mouseX = (typeof e != "undefined") ? e.pageX : event.clientX;
  var mouseY = (typeof e != "undefined") ? e.pageY : event.clientY;
  var divWidth = getimageobjnostyle().clientWidth;
  var divHeight = getimageobjnostyle().clientHeight;
  var scrollL = truebody().scrollLeft;
  var scrollT = truebody().scrollTop;
    
	var docwidth=document.all? scrollL+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	
  var positionLR = "right";
  var positionTB = "bottom";    
    
  var top = mouseY; 
  var bottom = docheight - mouseY;
  var left = mouseX;
  var right = docwidth - mouseX;
  if (right > divWidth + 10)
    {
        positionLR = "right";
        xcoord = scrollL+ mouseX + 10
    }
  else if (left > divWidth + 10)
    {
        positionLR = "left";
        xcoord = mouseX + scrollL - divWidth - 10;
    }
  else
    {
      if (left > right)
        {
            positionLR = "left";
            xcoord = mouseX + scrollL - divWidth - 10;
        }
      else
        {
            positionLR = "right";
            xcoord = scrollL+mouseX + 10
        }
    }
        
  if ( bottom > divHeight + 10)
    {
        positionTB = "bottom";
        ycoord += scrollT + mouseY + 10;
    }
  else
    {
        positionTB = "bottom";
        ycoord += scrollT + mouseY + 10;
    }

	if (xcoord + divWidth > docwidth  + scrollL)        xcoord = docwidth + scrollL - divWidth;
	if (ycoord + divHeight > docheight + scrollT)       ycoord = docheight + scrollT - divHeight;
	if (ycoord - scrollT < 0) 	   ycoord = scrollT; 
	if (xcoord - scrollL < 0)      xcoord = scrollL;

	getimageobj().left=xcoord+"px"
	getimageobj().top=ycoord+"px"
	if (getimageobj().display=="none")
		getimageobj().display="inline";
}

	// ------------------------------------------------------------------------------------
	// AJAX quand tu nous tiens
	// ------------------------------------------------------------------------------------
	
function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest){
  	xhr = new XMLHttpRequest(); 
		}
	else if(window.ActiveXObject){
		try {
     	xhr = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
    	xhr = new ActiveXObject("Microsoft.XMLHTTP");
      }
		}
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
		} 
  return xhr
	}

function update_sql(repertoire, photo) {
	var xhr = getXhr()
	xhr.onreadystatechange = function(){}
	xhr.open("GET","galerie-photo-update.php?r="+repertoire+"&p="+photo+"",true);
	xhr.send(null);
	}

function get_commentaire(repertoire, photo){

	}