//Function startList pour les rollover CSS UL/LI
//<span id="thescript" style="display: block; border: 1px solid #FF0000; padding: 10px; background: #FFFFCC;"></span>
//debug = document.getElementById("thescript");

startList = function() {
	//didI = false;
	navRoot = document.getElementById("nav");
	
	for (i=0; i<navRoot.childNodes.length; i++) {
		li = navRoot.childNodes[i];
		
		if (li.nodeName=="LI") {
			li.onmouseover=function() {
				//if(!didI){
					this.className+=" sfhover";
					if(document.all) this.style.zIndex=100;
					isItOutside(this);
					
					//didI=true;
				//}
  			}
  			//ul = (li.childNodes[2].tagName=="UL") ? li.childNodes[2] : li.childNodes[3];
			
			li.onmouseout=function() {
  				//this.parentNode.className=this.parentNode.className.replace("sfhover", "");
				this.className=this.className.replace("sfhover", "");
				//debug.innerHTML += this.parentNode.tagName + "<BR>";
				if(document.all) this.style.zIndex=1;
				//didI=false;
   			}
   		}
  	}
}
window.onload=startList;

function isItOutside(el){
	if(el.childNodes[1]){
		ul = (el.childNodes[1].tagName=="UL") ? el.childNodes[1] : el.childNodes[2];
		if(ul){
			menuWidth = ul.offsetWidth;
			titleOffset = el.offsetLeft;
			parentWidth = el.parentNode.offsetWidth;
			dist = parentWidth-(titleOffset+menuWidth);
			if(dist<0){
				aWidth = el.childNodes[0].offsetWidth;
				
				diff = (parentWidth-(titleOffset+aWidth))+Math.abs(dist);
				
				ulli = (ul.childNodes[0].tagName=="LI") ? ul.childNodes[0] : ul.childNodes[1];
				
				if(ulli.childNodes[1]){
					ulliul = (ulli.childNodes[1].tagName=="UL") ? ulli.childNodes[1] : ulli.childNodes[2];	
				
					
				
					ul.style.width="0px";
					if(ulliul) ulliul.style.left="-"+diff+"px";
				}else{
					if(ul.childNodes[1]) ul.style.left="-"+diff+"px";
				}
				titleA = ulli.childNodes[0];
			}
		}
	}
}
