////////////////////////////////////////////////////////////////////////////
//
// © PMP CONCEPT 2006 :: AGRANDISSEMENT DE LA PHOTO DE LA LISTE AVEC RESUME DES INFOS
//
////////////////////////////////////////////////////////////////////////////


var trailimage=["test.gif", 100, 99] //image path, plus width and height
var offsetfrommouse=[20,-30] //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0 //duration in seconds image should remain visible. 0 for always.
var showingHTML = false;
var currentimageheight = 355;	// maximum image size.

if (document.getElementById || document.all)
	document.write('<div id="trailimagediv"></div>')

function gettrailobj(){
	if (document.getElementById)
		return document.getElementById("trailimagediv").style
	else if (document.all)
		return document.all.trailimagid.style
}

function gettrailobjnostyle(){
	if (document.getElementById)
		return document.getElementById("trailimagediv")
	else if (document.all)
		return document.all.trailimagid
}

function showtrail(photo, nom, prix){
		document.getElementById('trailimagediv').innerHTML = '<img id="trailImg" src="'+photo+'" border="0"><div class="titre_promo">'+nom+'</div><div class="prix_promo_survol">' +prix+ '</div>';
		//document.getElementById('trailimagediv').style.visibility = 'visible';
		//gettrailobj().display="none";
		document.onmousemove=followmouse;
		//spéciale dédicace à IE qui ne prend pas le document.onmousemove si la souris est sur le 'trailimagediv'
		//simuleMouseMove();
}

function simuleMouseMove()
{
	/*alert("simulation");
	var evt = document.createEvent("MouseEvent");
	evt.initMouseEvent("mousemove", false, false, window, 0,
	0, 0, 0, 0, false, false, false, false, 0, null);
	document.dispatchEvent(evt);*/
}

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

function hidetrail(){
	gettrailobj().visibility="hidden"
	document.onmousemove="";
	
	//showElementsByTagName('SELECT');
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	
	if (typeof e != "undefined") // evenement capturé par Firefox
	{
		xcoord+=e.pageX
		ycoord+=e.pageY
	}
	else if (typeof window.event !="undefined") // évement capturé par IE
	{
		xcoord+=truebody().scrollLeft+event.clientX
		ycoord+=truebody().scrollTop+event.clientY
	}
	
	// taille et largeur de la page
	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)
	
	// correction de la hauteur du bloc
	// si le block descent trop bas alors on doir reajuster le positionnement
	
		var tailleEcran = truebody().clientHeight+truebody().scrollTop
		var tailleDiv = (document.getElementById('trailimagediv').clientHeight) + 7
		
		
		if(tailleEcran < tailleDiv + ycoord)
		{
			ycoord = ycoord - ((tailleDiv + ycoord) - tailleEcran)
		}
	
		
	// affichage du div
	if (xcoord+trailimage[1]+3>docwidth || ycoord+trailimage[2]> docheight)
		gettrailobj().display="none"
	else 
	{
		gettrailobj().visibility = 'visible';
		gettrailobj().display=""
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	
	refreshElementsByTagName('SELECT', "trailimagediv");
}


/* ===== Debogage mode techno pmp sous IE =====*/
//function trailimagediv_mousemove(e){
//	alert("toujours là");
//}

//document.getElementById("trailimagediv").onmousemove=trailimagediv_mousemove;

/* ===== Fin debogage =====*/


function refreshElementsByTagName(tagname,id)
{
	if(tagname==null)
		return;
	
	var elements = document.getElementsByTagName(tagname);
	
	var obj = document.getElementById(id);
	
	if(obj)
	{
		var top = obj.offsetTop;
		var bottom = obj.offsetTop + obj.offsetHeight;
		var left = obj.offsetLeft;
		var right = obj.offsetLeft + obj.offsetWidth;
		
		for (i = 0; i < elements.length; i++)
		{
			elemTop = elements[i].offsetTop;
			tempEl = elements[i].offsetParent;
			while (tempEl != null) {
				elemTop += tempEl.offsetTop;
				tempEl = tempEl.offsetParent;
			}
			elemBottom = elemTop + elements[i].offsetHeight;
			
			elemLeft = elements[i].offsetLeft;
			tempEl = elements[i].offsetParent;
			while (tempEl != null) {
				elemLeft += tempEl.offsetLeft;
				tempEl = tempEl.offsetParent;
			}
			elemRight = elemLeft + elements[i].offsetWidth;
			
			if( ((elemTop > top && elemTop < bottom) || (elemBottom > top && elemBottom < bottom)) &&
				((elemLeft > left && elemLeft < right) || (elemRight > left && elemRight < right)) )																			
				elements[i].style.visibility = 'hidden';
			else
				elements[i].style.visibility = 'visible';
		}
	}
}


if (displayduration>0)
setTimeout("hidetrail()", displayduration*1000)
