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

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);

	currentimagewidth = zwidth;
	currentimageheight = zheight;
	
	hScreenSecurity = currentimagewidth;
	vScreenSecurity = currentimageheight;
	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-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"
}



/****************************************************/
/*				CUSTOM PLAN BATEAU					*/
/****************************************************/
function customVignettesFlotte() {
	if($('rub_flotte')) {
		$$('#rub_flotte a').each(function(s) {
			s.currentImg = '';
			s.descendants().each(function(n) {
				if(n.nodeName == 'IMG') s.currentImg = n;
			});
			s.newImgSrc = s.currentImg.src.replace(/_carre/, "_vignette");
			var newImg = document.createElement('img');
			newImg.className = 'imgOver';
			newImg.src = s.newImgSrc;
			s.parentNode.appendChild(newImg);
			
			s.onmouseover = function() {
				showtrail(this.newImgSrc,'','',0);
			}
			s.onmouseout = function() {
				hidetrail();
			}
		});
	}
}

/****************************************************/
/*				INITIALISATION DE LA PAGE			*/
/****************************************************/
function addLoadListenerBateaux(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) {
	addLoadListenerBateaux(function() {
		customVignettesFlotte();
	});
}