// JavaScript Document

function initPop() {
	$$('table a.pop').each(function(s) {
		s.onmouseover = function() {
			showtrail(this);
		}
		s.onmouseout = function() {
			hidetrail();
		}
		s.onclick = function() {
			void(0);
			return false;
		}
	});
	$$('img.pop').each(function(s) {
		s.onmouseover = function() {
			showtrail(this);
		}
		s.onmouseout = function() {
			hidetrail();
		}
		s.onclick = function() {
			void(0);
			return false;
		}
	});
}


/****************************************************/
/*					GESTION DU ZOOM					*/
/****************************************************/
var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var hScreenSecurity = 20;
var vScreenSecurity = 40;

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

function showtrail(elt){
	// création du conteneur de zoom
	var conteneurZoom = (elt.nodeName == 'IMG')?document.createElement('img'):document.createElement('iframe');
	conteneurZoom.id = 'trailimageid';
	conteneurZoom.src = (elt.nodeName == 'IMG')?elt.src:elt.href;
	if(elt.nodeName == 'IMG') {
		conteneurZoom.style.width = "auto";
		conteneurZoom.style.height = "auto";
	}
	document.body.appendChild(conteneurZoom);
	document.onmousemove=followmouse;
}

function hidetrail(){
	document.onmousemove=killfollowmouse;
	var eltTrail = document.getElementById('trailimageid');
	if(eltTrail) document.body.removeChild(eltTrail);
}

function killfollowmouse(e) {
}

function followmouse(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth;
	var docheight = document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);

	if (typeof e != "undefined"){	// MOZILLA
		if (docwidth - e.pageX < ($("trailimageid").getWidth() + hScreenSecurity)){
			xcoord = e.pageX - xcoord - $("trailimageid").getWidth(); // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < ($("trailimageid").getHeight() + vScreenSecurity)){
			ycoord += e.pageY - Math.max(0,(vScreenSecurity + $("trailimageid").getHeight() + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){		// IE
		if (docwidth - event.clientX < ($("trailimageid").getWidth() + hScreenSecurity)){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - $("trailimageid").getWidth(); // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < ($("trailimageid").getHeight() + vScreenSecurity)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(vScreenSecurity + $("trailimageid").getHeight() + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }
	
	$("trailimageid").style.left=xcoord+"px";
	$("trailimageid").style.top=ycoord+"px";
}

