/*
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		= 30;	//duration in seconds image should remain visible. 0 for always.
var currentimageheight	= 100;	// maximum image size. -> 200 (170)
var image_to;
var opacity = 90 ;
var decale = 2 ;

var largec = screen.width ;
var mitest = screen.width ;
var mitest = mitest / 2 ;
var mitest = mitest - 12 ;

if ( largec > 900 )
{
	var mitest = mitest - 75 ;
}

//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(type,message,titre,descri,auteur,sstitre,ssdescri,infos,stats)
{

	document.onmousemove=followmouse;

	if ( type == "1" )
	{
		newHTML = '<div style="padding: 4px;" class="trailimagediv2">';
	  newHTML = newHTML + '<center>' + message + '</center>'; 
	}
	else {
		newHTML = '<div style="padding: 4px;" class="trailimagediv">';
      if (titre)
         newHTML = newHTML + '<span style="font-size:1.25em;"><b><center>' + titre + '</center></span></b>';

      if ( descri )
         newHTML = newHTML + descri + '<br />';
				 
      if (auteur)
         newHTML = newHTML + '<br /><b>' + auteur + '</b><br />';

      if ( sstitre)
         newHTML = newHTML + '<br />' + sstitre + '<br />';

      if ( ssdescri)
         newHTML = newHTML + ssdescri + '<br />';

      if ( infos)
         newHTML = newHTML + '<br />' + infos + '<br />';

      if ( stats)
         newHTML = newHTML + stats + '<br />';
				 
			if ( message)
      newHTML = newHTML + '<br /><center>' + message + '</center>'; 
	}
	//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 - 350; // 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 - 350; // 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 + 14;
      xcoord = xcoord - decale + 2
	
	gettrailobj().left = xcoord + "px";
	gettrailobj().top = ycoord + "px";

}