/*	Evènements
Webmanager © Lezartcom
*/
N = (navigator.appName=="Netscape") ? 1 : 0;
var idObj;
var FF = (navigator.userAgent.indexOf("Firefox")>-1 || navigator.userAgent.indexOf("Safari")>-1) ? 1 : 0;
var ssX; // Sauvegarde de la position de la souris lors du mousedown
var ssY;
var X;
var Y;
var ssX; // Sauvegarde de la position de la souris lors du mousedown
var ssY;
var idR=0;

if(ie){
	window.attachEvent("onload", evenement);
}
else{
	window.addEventListener("load", evenement, false);
}

function evenement(){
	if(ie){
		GetE('nav').attachEvent('onmouseover', setIdObj) ;
		GetE('navSec').attachEvent('onmouseover', cacheNav) ;
		GetE('contenu').attachEvent('onmouseover', cacheNav) ;
		
			
	}
	else{
		GetE('nav').addEventListener('mouseover', setIdObj, false) ;
		GetE('navSec').addEventListener('mouseover', cacheNav, false) ;
		GetE('contenu').addEventListener('mouseover', cacheNav, false) ;
	}
	if(GetE('encartFiche')){
		getFiche();
	}
}
var delay = 10;
var maxtop = 100;
var maxbas = 500;
var position="haut";
function setIdObj(e){
	if (N) {
		idObj = e.id;
		X=e.x;
		Y=e.y;
		if (FF) {
			idObj = e.target.id;
			ssX = e.clientX;
			ssY = e.clientY;
			X = e.clientX + self.pageXOffset - e.target.offsetLeft;
			Y = e.clientY + self.pageYOffset - e.target.offsetTop;
		}
	}
	else {
		idObj = event.srcElement.id;
		ssX = event.clientX;
		ssY = event.clientY;
		X=event.offsetX;
		Y=event.offsetY;
	}
	if(idObj.substring){
		
		if(idObj.substring(0,3)!="nav" && idObj!="" && GetE("nav"+idR)){
			GetE("nav"+idR).style.display='none';
		}
		if (idObj.substring(0,6)=="navImg") {
			if(GetE("nav"+idR)){
				GetE("nav"+idR).style.display='none';
			}
			idR=idObj.substring(6);
			if(GetE("nav"+idR)){
				GetE("nav"+idR).style.display='block';
			}
	
		}
		if (idObj.substring(0,7)=="navHref") {
	
			if(GetE("nav"+idR)){
				GetE("nav"+idR).style.display='none';
			}
			idR=idObj.substring(7);
	
			if(GetE("nav"+idR)){
				GetE("nav"+idR).style.display='block';
				//mLeft = Math.round((ssX-30)/30)*30;
				//GetE("nav"+idR).style.margin='0 0 0 '+(mLeft)+'px';
			}
		}
	}
}
function cacheNav(){
	if(GetE("nav"+idR)){
		GetE("nav"+idR).style.display='none';
	}
}
function depliNav(){
	objettop=GetE("nav").style.top.substring(0,GetE("nav").style.top.indexOf("px"))/1;
	objetopac=GetE("contenu").style.opacity/1;
	//GetE("bas").innerHTML=objetopac
	if(position=="bas"){
		if(objettop>maxtop){
			setTimeout("depliNav()", delay);
			moveNav(-10);
			if(objetopac>0)
				GetE("contenu").style.opacity=objetopac-0.2;
		}
		else{
			GetE("nav").style.top=maxtop+"px";
			position="haut";
			GetE("contenu").style.opacity=0;
			document.location.href='index.php?idR='+idR+'&lang=fr';
			//setTimeout("depliNav()", 1000);
		}

	}
	else{
		if(position=="haut"){
			if(objettop<maxbas){
				setTimeout("depliNav()", delay);
				moveNav(10);
				if(objetopac<1){
					GetE("contenu").style.opacity=objetopac+0.2;
				}
			}
			else{
				GetE("nav").style.top=maxbas+"px";
				position="bas";
			}
		}
	}
}
function moveNav(val){
	objettop=GetE("nav").style.top.substring(0,GetE("nav").style.top.indexOf("px"))/1;
	GetE("nav").style.top=objettop+val+"px";
}


var tpsFiche=3;
var titre = '';
var photo = '';
function getFiche(){

	http.open("GET", racine+'ajax/encartFiche.php?idR='+idR, true);
	http.onreadystatechange = chargeFiche;
	http.send(null);

}
function chargeFiche(){
	if(http.readyState == 4){
		if (http.status == 200) {

			xml = http.responseXML;

			if(xml==null){
				
			}
			else{
				liste = xml.getElementsByTagName('bateaux');
				champs = liste[0].childNodes[0].attributes;
				imageACharger = new Image;
				imageACharger.src = champs[1].value;
				
				titre = '<img src="'+champs[2].value + '" /> <a href="'+champs[0].value+'">' +liste[0].childNodes[0].firstChild.nodeValue+ '</a>';
				photo = '<a href="'+champs[0].value+'"><img src="'+champs[1].value + '" /></a>';
				setTimeout("afficheFiche()", tpsFiche*1000);
			}
   		}
	}
}
function afficheFiche(){
	GetE('titre').innerHTML = titre;
	GetE('photo').innerHTML = photo;
	getFiche();
}