onload = windowonload;
currDrop = "";

function windowonload(){
	var xmlDoc = loadXMLDoc("menuHome.xml");
	var menuHolder = gebi('holdMenu');
	var links = xmlDoc.getElementsByTagName("siteMapNode"); //Get all site Nodes
	//alert(links.length);
	for (var i=0;i<links.length;i++){
		var url = links[i].getAttribute('url'); //What is the HREF?
		var title = links[i].getAttribute('title'); 
		var description = links[i].getAttribute('description'); //And the Mouseover Text
		
		if (links[i].parentNode.nodeName == "siteMap"){ //Check if it is the main one
			if(url!="customers.aspx"){
				//menuHolder.innerHTML+="<a href='#' onclick='showDrop(\""+title+"\")'  id='"+title+"' title='"+title+"' class='mainLink' >"+title+"</a>";
				menuHolder.innerHTML+="<a href='"+url+"' title='"+description+"' id='"+title+"' class='mainLink'>"+title+"</a>";
			}else{
				menuHolder.innerHTML+="<a href='"+url+"' title='"+description+"' id='"+title+"' class='mainLink'>"+title+"</a>";
			}
		}else{
			var myHeight = 0;
			var myId = links[i-1].getAttribute('title');
			myId+="Down";
			menuHolder.innerHTML+="<div id='"+myId+"' class='drops' style='display:none;overflow:hidden;'>";
			while(links[i].parentNode.nodeName != "siteMap"){
				var url = links[i].getAttribute('url'); //What is the HREF?
				var title = links[i].getAttribute('title'); 
				var description = links[i].getAttribute('description'); //And the Mouseover Text
				document.getElementById(myId).innerHTML+="<a href='"+url+"' id='"+title+"' title='"+description+"' class='smallLink' >"+title+"</a>";
				myHeight++;
				i++;
				if(i==links.length)break;
			}
			document.getElementById(myId).style.height=myHeight*16;
			if(i!=links.length)i--;
			menuHolder.innerHTML+="</div>";
		}
	}
	checkIf();
}

function showDrop(id){
	var _linksHolder = document.getElementById('holdMenu'); //Get the DIV's DOM
	var _allLinks = _linksHolder.getElementsByTagName("a"); //Get all links
	for(var i=0;i<_allLinks.length;i++){
		if(_allLinks[i].className=='focusLinksM'){
			_allLinks[i].className = 'mainLink';
		}
	}
	gebi(id).className="focusLinksM";
	id+="Down";
	if(document.getElementById(id)){
		if(currDrop != ""){
			closeDrop(currDrop,document.getElementById(currDrop).style.height);
		}
		if(currDrop == id){
			currDrop="";
			return false;
		}
		idObj = document.getElementById(id);
		var height = idObj.style.height;
		idObj.style.height="0px";
		idObj.style.display="";
		currDrop = id;
		animateDrop(id,height);
	}
}

function animateDrop(id,height){
	idObj = document.getElementById(id);
	var pxHeight = idObj.style.height;
	var rHeight = new Array;
	rHeight = pxHeight.split("p");
	idObj.style.height = parseInt(rHeight[0])+8;
	if (idObj.style.height!=height){
		timer = setTimeout("animateDrop('"+id+"','"+height+"')",1);
	}else{
		isClose=0;
	}
}

function closeDrop(id,height){
	idObj = document.getElementById(id);
	var pxHeight = idObj.style.height;
	var rHeight = new Array;
	rHeight = pxHeight.split("p");
	idObj.style.height = parseInt(rHeight[0])-8;
	if (idObj.style.height!="0pt" && idObj.style.height!="0px"){
		timer = setTimeout("closeDrop('"+id+"','"+height+"')",1);
	}else{
		idObj.style.display="none";
		idObj.style.height=height;
		idObj.style.display="none";
		var newId="";
		for(var i=0;i<=id.length-5;i++) newId+=id.charAt(i);
	}
}
function checkIf(){
	//This REQUIRES your ATTENTION
	var qs = document.pageID;
	if (qs == undefined) {
	    qs = "";
	}
	//qs = "Services and Support";
	var qsArr = new Array;
	qsArr = qs.split("/");
	pID = qsArr[0];
	var lID = qsArr[1]
	if (pID!=""){
		if(document.getElementById(pID+"Down")){
			document.getElementById(pID+"Down").style.display = "";
			currDrop = pID+"Down";
			gebi(pID).className='focusLinksM';
		}
		if (lID!="" && lID!=undefined){
			currLink=lID;
			gebi(currLink).className='focusLinksS';
		}
	}
	
	if (pID=="Our Customers"){
		gebi(pID).className='focusLinksM';	
	}

}

function gebi(id){
	return document.getElementById(id);
}

function loadXMLDoc(dname){
	var xmlDoc;
	if (window.ActiveXObject){
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}else if (document.implementation && document.implementation.createDocument){
		xmlDoc=document.implementation.createDocument("","",null);
	}else{
		return;
	}
	xmlDoc.async=false;
	xmlDoc.load(dname);
	return xmlDoc;
}
