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

function prepareZoom() {
	if(document.getElementById('con_descriptif')) {
		var tabPhotos = document.getElementById('con_descriptif').getElementsByTagName('a');
		var tabPhotosZoom = new Array;
		for(iP=0; iP<tabPhotos.length; iP++){
			if(tabPhotos[iP].getAttribute('rel') == 'lightbox[roadtrip]')
				tabPhotosZoom.push(tabPhotos[iP]);
		}
		for(iPZ=0; iPZ<tabPhotosZoom.length; iPZ++) {
			var urlZoom = tabPhotosZoom[iPZ].href;
			tabPhotosZoom[iPZ].urlZoom = urlZoom;
			tabPhotosZoom[iPZ].onmouseover = function() {
				var w = 0;
				var h = 0;
				if(this.firstChild.width>this.firstChild.height) w = 300;
				else h = 500;
				showtrail(this.urlZoom,this.firstChild.getAttribute('alt'),'',w,h);
			}
			tabPhotosZoom[iPZ].onmouseout = function() {
				hidetrail();
			}
		}
	}
}

function gettrailobj(){
	return document.getElementById("trailimageid").style;
}

function gettrailobjnostyle(){
	return document.getElementById("trailimageid");
}

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

function showtrail(imagename,title,description,zwidth,zheight){
	// création du conteneur de zoom
	var conteneurZoom = document.createElement('div');
	conteneurZoom.id = 'trailimageid';
	document.body.appendChild(conteneurZoom);
	// création du titre s'il est rempli
	if(title != '') {
		var titreZoom = document.createElement('h2');
		conteneurZoom.appendChild(titreZoom);
		var txtTitreZoom = document.createTextNode(title);
		titreZoom.appendChild(txtTitreZoom);
	}
	// création du descriptif s'il est rempli
	if(description != '') {
		var descZoom = document.createElement('p');
		conteneurZoom.appendChild(descZoom);
		var txtDescZoom = document.createTextNode(description);
		descZoom.appendChild(txtDescZoom);
	}
	// création de l'image
	var imgZoom = document.createElement('img');
	imgZoom.setAttribute('src',imagename);
	imgZoom.id = 'imgZoom';
	imgZoom.setAttribute('alt',description);
	conteneurZoom.appendChild(imgZoom);
	if (zwidth > 0){
		currentimagewidth = zwidth;
		currentimageheight = (currentimagewidth/imgZoom.width) * imgZoom.height;
		imgZoom.setAttribute('height',currentimageheight);
		imgZoom.setAttribute('width',currentimagewidth);
	}
	if (zheight > 0){
		currentimageheight = zheight;
		currentimagewidth = (currentimageheight/imgZoom.height) * imgZoom.width;
		imgZoom.setAttribute('height',currentimageheight);
		imgZoom.setAttribute('width',currentimagewidth);
	}
	
	hScreenSecurity = currentimagewidth;
	document.onmousemove=followmouse;
}

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

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-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

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

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

/****************************************************/
/*		CUSTOMISATION DES LIENS PARTENAIRES			*/
/****************************************************/
function customPartenaires() {
	var labels = document.getElementById('menu_menupartenaireslabels').lastChild.childNodes;
	var cg = document.getElementById('menu_menupartenairescg').lastChild.childNodes;
	for(iL=0; iL<labels.length; iL++) {
		// suppression des textes sur les liens
		labels[iL].firstChild.firstChild.removeChild(labels[iL].firstChild.firstChild.lastChild);
	}
	for(iCG=0; iCG<cg.length; iCG++) {
		// suppression des textes sur les liens
		cg[iCG].firstChild.firstChild.removeChild(cg[iCG].firstChild.firstChild.lastChild);
	}
}



//*******************************//
// lancement des init de la page //
//*******************************//
function addLoadListenerPage(func) {
	if (window.addEventListener) {
		window.addEventListener("load", func, false);
	} else if (document.addEventListener) {
		document.addEventListener("load", func, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", func);
	}
}

if (document.getElementById && document.createTextNode) {
	addLoadListenerPage(function() {
		//customPartenaires();
		prepareZoom();
	});
}
