//if (typeof BrowserDetect == "undefined")
//    document.write("<script src='includes/javascript/browser_detect.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.trailimagid.style
}

function getimageobjnostyle()
{
    if (document.getElementById)
        return document.getElementById("Myimageid")
    else if (document.all)
        return document.all.trailimagid
}

function truebody()
{
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showImage(imagename){

	// ajout perso : mise à jour bd
	perso_lien = imagename;
	pos_depart = perso_lien.indexOf('?fichier=');
	nom_temp = perso_lien.substr(pos_depart + 10);
	pos_fin = nom_temp.indexOf('/');
	nom_repertoire = nom_temp.substr(0, pos_fin);
	nom_image = nom_temp.substr(pos_fin + 1);
	update_sql(nom_repertoire, nom_image);

	document.onmousemove=followmouse;
  newHTML = '<div style="padding: 0px; background-color: #151515; border: 1px solid #000000;">';
  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;
	}

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";
}

function update_sql_1(repertoire, photo) {
	var xhr = getXhr()
	xhr.onreadystatechange = function(){}
	xhr.open("GET","updateimage.php?r="+repertoire+"&p="+photo+"",true);
	xhr.send(null);
	}
