/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

/* on utilisera la syntaxe prototype : $('mydivID') <=> document.getElementById('mydivID') */

var offsetfrommouse = [15,-200];		// espace entre le curseur de la souris et l'image
var displayduration = 0;					// duree pendant laquelle reste présente l'image, mettre 0 pour toujours
var currentimageheight = 400;			// taille de l'image

if (document.getElementById || document.all) {
		document.write('<div id="trailimagediv">');
		document.write('</div>');
}


function truebody() {
		return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

/* la fonction appartition de la popup */
function showtrail(imagename,brand,label,price,height) {
		if (height > 0){
				currentimageheight = height;
		}
		document.onmousemove = followmouse;
		$('trailimagediv').innerHTML = '<img id="trailImg" src="' + imagename + '" border="0" class="bigarticleimg">';//<div class="brand">'+brand+'</div><div class="label">'+label+'</div><div class="price">'+price+'</div>';
		$('trailimagediv').style.visibility = 'visible';
		
		// effet de fondu sur le contenu du div :
		//Effect.Appear('trailDiv', {duration:1.5, from:0.0, to:1.0} );
		//Effect.Grow('trailDiv', {direction: 'center'} );
}

/* disparition de la popup */
function hidetrail() {
		$('trailimagediv').style.visibility = 'hidden';
		document.onmousemove = '';
		$('trailimagediv').style.left = '-500px';
}

function followmouse(e) {

		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);
		var docwidth = document.all? truebody().scrollHeight+truebody().clientHeight : pageYOffset+window.innerHeight-15;
		if (docwidth > 955) {
				docwidth = 955;
		}
		
		/* ff */
		if (typeof e != "undefined") {
				if (docwidth - e.pageX < 420) {
						xcoord = e.pageX - xcoord - 420; // Move to the left side of the cursor
				} else {
						xcoord += e.pageX;
				}
				//if (docheight - e.pageY < (currentimageheight + 50)){
				if (docheight - e.pageY < (currentimageheight + 110)){
						ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
						//ycoord += e.pageY - Math.max(0,(50 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
				} else {
						ycoord += e.pageY;
				}
		/* ie */
		} else if (typeof window.event != "undefined") {
				if (docwidth - event.clientX < 420) {
						xcoord = event.clientX + truebody().scrollLeft - xcoord - 420; // Move to the left side of the cursor
				} else {
						xcoord += truebody().scrollLeft+event.clientX
				}
				//if (docheight - event.clientY < (currentimageheight + 50)) {
				if (docheight - event.clientY < (currentimageheight + 110)) {
						//ycoord += event.clientY + truebody().scrollTop - Math.max(0,(50 + currentimageheight + event.clientY - docheight));
						ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + 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*-1;
		}
		$('trailimagediv').style.left = xcoord+"px";
		$('trailimagediv').style.top = ycoord+"px";

}