//<!--
// Menu déroulant des entetes Version 1.0
// (C) SQLPAC 2010.  
//
// Revision dd mm YYYY	
//
//
//
function isChildOf(ChildObject,ContainerObject) { 
     var curobj; 
     if(typeof(ContainerObject)=="string")
     {        ContainerObject=document.getElementById(ContainerObject);    }
     if(typeof(ChildObject)=="string")
     {        ChildObject=document.getElementById(ChildObject);    }
     if(ChildObject == undefined) {
    	 return false;
     }
     for(curobj=ChildObject.parentNode; ( (curobj!=undefined) && (curobj!=document.body) &&(curobj.id!=ContainerObject.id) );curobj=curobj.parentNode)
     {    }
     if(curobj == null) return false;
     return (curobj.id==ContainerObject.id);
}

function hideAllMegaMenus() {
	if(allHeaderMenus) {
		for(var i =0; i < allHeaderMenus.length; i++) {
			allHeaderMenus[i].hideMenu();
		}
	}
}

var allHeaderMenus = new Array();
function HeaderMenu(menuId, headerItem) {
	headerItem.megaDiv = document.getElementById("mega" + menuId);
	headerItem.hatDiv = document.getElementById("hat" + menuId);
	headerItem.linkDiv = document.getElementById("link" + menuId);
	headerItem.style.width = (headerItem.offsetWidth - 2) +'px';
	headerItem.isOpen = false;
	headerItem.originalBackground = headerItem.style.backgroundColor;
	headerItem.megaDiv.headerItem = headerItem;
	headerItem.megaDiv.onmouseout = function(e) {
		this.headerItem.hideMenu(e);
	};
	headerItem.shim = document.getElementById("shim");
	allHeaderMenus[allHeaderMenus.length] = headerItem;
	
	
	
	headerItem.initMenus = function() {
		this.div.style.display = "none";
	}
	
	headerItem.showMenu = function(e) {
		if(!this.isOpen) {
			this.megaDiv.style.left = getLeftPosition(this) + "px" ; //Set my leftside to my parent's left, so I slide from the left
			var topPosition = this.offsetHeight + getTopPosition(this) -3;
			this.megaDiv.style.top = topPosition + "px";
			this.megaDiv.style.display = "block";
			this.megaDiv.style.visibility = "hidden";
			this.megaDiv.style.width = this.megaDiv.offsetWidth+'px';
			this.megaDiv.style.visibility = "visible";
			this.hatDiv.style.display = "block";
			this.style.background = "#a3a3a7";
			this.style.borderTopColor="#c0c0c0";
			this.style.borderLeftColor="#c0c0c0";
			this.style.borderRightColor="#c0c0c0";
			this.linkDiv.style.color = "#FFF8C6";
			/** this.linkDiv.style.color = "#FFF"; */
			this.isOpen = true;
			if(this.shim) {
				this.shim.style.width = this.megaDiv.offsetWidth+'px' ;
				this.shim.style.height = this.megaDiv.offsetHeight+'px' ;
				this.shim.style.top = this.megaDiv.offsetTop+'px';
				this.shim.style.left = this.megaDiv.offsetLeft+'px';
				this.shim.style.display = "block";
			}			
		}
	}
	
	headerItem.hideMenu = function(e) {
		if(!e) e= window.event;
		var target;
		var close = false;
		if(!e) {
			if(this.isOpen) close = true;
		} else {
			if(e.relatedTarget) {
				target = e.relatedTarget;
			}
			else {
				target = e.toElement;
			}
		}
		
		if(close || (this.isOpen && target != this && target != this.megaDiv)) {
			if(close || (!isChildOf(target, this) &&  !isChildOf(target, this.megaDiv))) {
				this.megaDiv.style.visibility = "hidden";
				this.megaDiv.style.display = "none";
				this.hatDiv.style.display = "none";
				this.style.background = this.originalBackground;
				this.style.borderLeftColor= this.originalBackground;
			    this.style.borderRightColor= this.originalBackground;
				this.linkDiv.style.color = "#FFFFFF";
				this.isOpen = false;
				if(this.shim) this.shim.style.display="none";
			}
		}
	}	
}
