/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

/*
Modified and adapted for http://www.ecranplus.net
This notice must stay intact
*/

var offsetfrommouse		=[5,1];	//image x,y offsets from cursor position in pixels. Enter 0,0 for no offset --> 2,2
var displayduration		= 10;	//duration in seconds image should remain visible. 0 for always.
var currentimageheight	= 170;	// maximum image size. -> 200
var image_to;
var opacity = 90 ;
var decale = 0 ;

if ( screen.width > 800 )
{
   var decale = screen.width - 800 ;
   var decale = decale / 2 ;
}

var mitest = 380 + decale ;

if (document.getElementById || document.all)
{
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

function gettrailobj()
{
	if (document.getElementById)
		return document.getElementById("trailimageid").style
	else if (document.all)
		return document.all.trailimagid.style
}

function gettrailobjnostyle()
{
	if (document.getElementById)
		return document.getElementById("trailimageid")
	else if (document.all)
		return document.all.trailimagid
}


function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function showtrail(ref,titre,auteur,descri,option,message)
{
	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 4px;" class="trailimagediv">';
	newHTML = newHTML + 'Réf : ' + ref + '<br />';
      if (titre)
         newHTML = newHTML + '<span style="font-size:1.25em;"><b>' + titre + '</span></b><br />';

      if (auteur)
         newHTML = newHTML + '<b>' + auteur + '</b><br />';

      if ( descri )
         newHTML = newHTML + '<br /><b>' + descri + '</b><br />';

      if ( option)
         newHTML = newHTML + '<br />' + option + '<br />';

      newHTML = newHTML + '<br />' + message + '<br />'; 

	//if (showthumb == true)
	//	newHTML = newHTML + '<img src="' + imagename + '" height="' + height + '" border="0">';

	newHTML = newHTML + '</div>';

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";
	
    gettrailobj().opacity = (opacity / 100); 
    gettrailobj().MozOpacity = (opacity / 100); 
    gettrailobj().KhtmlOpacity = (opacity / 100); 
    gettrailobj().filter = "alpha(opacity=" + opacity + ")"; 

	if(displayduration != 0)
		image_to = window.setTimeout('hidetrail()', displayduration * 1000);
}


function hidetrail()
{
	if(displayduration != 0)
		window.clearTimeout(image_to);
	
	gettrailobj().visibility="hidden";
	document.onmousemove="";
	gettrailobj().left="-500px";
}

function followmouse(e)
{
	if(displayduration != 0) {
		window.clearTimeout(image_to);
		image_to = window.setTimeout('hidetrail()', displayduration * 1000);
	}
	
	var xcoord = offsetfrommouse[0];
	var ycoord = offsetfrommouse[1];

	var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15;
	var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < mitest){
			xcoord = e.pageX - xcoord - 355; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight)){
			ycoord += e.pageY - Math.max(0,(currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < mitest){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 355; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15;
	var docheight = document.all ? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
	
	if(ycoord < 0)
		ycoord = ycoord * -1;

      ycoord = ycoord - 120;
      xcoord = xcoord - decale
	
	gettrailobj().left = xcoord + "px";
	gettrailobj().top = ycoord + "px";

}
