function showWWMenu() {
	hideAllMegaMenus();
	var menu = document.getElementById('worldwide_sub');
	var iframe = document.getElementById('worldwide_subIFrame');
	var wwTitle = document.getElementById('wwTitle');
	var bottom = getTopPosition(wwTitle) + 12;
	var left = getLeftPosition(wwTitle);
	menu.style.top = bottom + "px";
	menu.style.left =left + "px";
	menu.style.display='block';
	if(iframe != null) {
		iframe.style.width = menu.offsetWidth+'px';
		iframe.style.height = menu.offsetHeight+'px';
		iframe.style.top = menu.offsetTop+'px';
		iframe.style.left = menu.offsetLeft+'px';
		iframe.style.display = "block";
	}
	
}

function hideWWMenu() {
	document.getElementById('worldwide_sub').style.display = "none";
	var iframe = document.getElementById('worldwide_subIFrame');
	if(iframe != null) {
		iframe.style.display = "none";
	}
}

addLoadEvent(function() {
	if (document.getElementById) {
		var navRoot = document.getElementById("nav");
		for (i=0; i < navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI" && node.id) {
				if(document.getElementById("mega" + node.id)) {
					var menu = HeaderMenu(node.id, node);
					node.onmouseover= function(e) {
						this.showMenu(e);
					};
					node.onmouseout = function(e) {
						this.hideMenu(e);
					};
				}
			}
		}
	}
})

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 = "#FFFFFF";
			this.style.borderLeftColor="#A1A1A1";
			this.style.borderRightColor="#A1A1A1";
			this.linkDiv.style.color = "#333333";
			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";
			}
		}
	}	
}