

// dropdown menu code
if(document.all)  //this is suppose to fix IE6
{
	var ulcollection = document.getElementsByTagName("UL");
	
	for (var ulcount=0; ulcount<ulcollection.length; ulcount++)
	{
		if(ulcollection[ulcount].className == "menu")
		{
			//ulcollection[ulcount].className = "ulmouseout";
			var innerul = ulcollection[ulcount].getElementsByTagName("UL");
			for(var inulcount=0; inulcount<innerul.length; inulcount++)
			{
				//alert(innerul[inulcount].tagName);
				innerul[inulcount].className = "ulmouseout";
			}
		}
	}
}

if(1)
{
	var ulcollection = document.getElementsByTagName("UL");
	
	for (var ulcount=0; ulcount<ulcollection.length; ulcount++)
	{
		if(ulcollection[ulcount].className == "menu")
		{
			
			var licollection = ulcollection[ulcount].getElementsByTagName("LI");
			
			for (var licount=0; licount<licollection.length; licount++)
			{
				//alert("test");
				//licollection[licount].className = "limouseover";
				
				licollection[licount].onmouseover = function()
				{
					//if(this.id != "menu") return;  // get out of this event if not a dropdown menu LI
					if(document.all) this.className = "limouseover";
					//window.status = this.tagName;
					//alert(this.id);
					
					//for(var i=0; i<this.childNodes.length; i++)
					//{
						////alert(this.childNodes[i].tagName);
						//if(this.childNodes[i].tagName == "A") 
						//{
							////alert(this.childNodes[i].href)
							//this.setAttribute("href", this.childNodes[i].href);
							////this.childNodes[i].removeNode();
							////this.removeChild(this.childNodes[i]);
							//this.onmousedown = function()
							//{
								//gotoURL(this.getAttribute("href"));
							//}
						//}
					//}
					var ulcollection = this.getElementsByTagName("UL");
					
					for (var ulcount=0; ulcount<ulcollection.length; ulcount++)
					{
						if(ulcollection[ulcount].parentNode == this)
						{
							if(document.all) ulcollection[ulcount].className = "ulmouseover";
						}
					}
				}
				licollection[licount].onmouseout = function()
				{
					//alert("moused");
					//if(this.id != "menu") return;  // get out of this event if not a dropdown menu LI
					if(document.all) this.className = "limouseout";
					var ulcollection = this.getElementsByTagName("UL");
					
					for (var ulcount=0; ulcount<ulcollection.length; ulcount++)
					{
						if(ulcollection[ulcount].parentNode == this)
						{
							if(document.all) ulcollection[ulcount].className = "ulmouseout";
						}
					}
				}
			}
		}
	}
}



// root menu items are inside SPAN tags with class "menulink"

var allspans = document.getElementsByTagName("SPAN");

for (var y=0; y<allspans.length; y++)
{
	if(allspans[y].className == 'menulink')
	{
		//targetspanID = allspans[y].id.replace(/link_/,"");
		//targetspanObj = document.getElementById(targetspanID);
		
		targetmenuID = allspans[y].id.replace(/link/,"menu");
			
		targetmenuObj = document.getElementById(targetmenuID);
		
		for(var n=0; n<targetmenuObj.childNodes.length; n++)
		{
			//alert(targetmenuObj.childNodes[n].tagName);
			
			//targetmenuObj.childNodes[n].id = "menu";
			if(targetmenuObj.childNodes[n].tagName == 'UL')
			{
				targetmenuObj.childNodes[n].className = "menu";
			}
			/*nextlevel = targetmenuObj
			while(nextlevel.childNodes.length > 0)
			{
				for(var m=0; m<nextlevel.childNodes.length; m++)
				{
					//nextlevel.childNodes[n].id = "menu";
				}
				nextlevel = nextlevel.childNodes[n];
			}*/
			//alert(targetmenuObj.childNodes[n].id);
		}
			
		allspans[y].onmouseover = function()
		{
		
			//alert('mouseover');
			targetmenuID = this.id.replace(/link/,"menu");
			
			targetmenuObj = document.getElementById(targetmenuID);
			
			//alert(this.offsetTop);
			var ycoord = 0;
			var xcoord = 0;
			var bodyObj = this;
			do
			{
				//alert('before step: ' + bodyObj.tagName);
				ycoord = ycoord+bodyObj.offsetTop;
				xcoord = xcoord+bodyObj.offsetLeft;
				//bodyObj = bodyObj.offsetParent;
				//alert('after step: ' + bodyObj.tagName);
				//alert(bodyObj.offsetTop);
			} while(bodyObj = bodyObj.offsetParent)
			
			//alert('after while loop');
			var scrolldiff = 0;
			var scrolltopdiff = 0;
			
			var browser = navigator.userAgent;

			if(browser.toLowerCase().indexOf('safari') > 0)
			{
				bodyscrolltop = document.body.scrollTop;
			}
			else
			{
				bodyscrolltop = document.documentElement.scrollTop;
			}
			if(bodyscrolltop <= 0)
			{
				//scrolldiff = 0;
				scrolldiff = parseInt(document.getElementById('menubar').offsetLeft);
			}
			else
			{
				scrolldiff = parseInt(document.getElementById('menubar').offsetLeft);
			}
			
			if(browser.toLowerCase().indexOf('opera') >= 0)
			{
				targetmenuObj.style.top = (this.offsetTop-1).toString() + 'px'; //(this.offsetHeight-1).toString() + 'px';
			}
			else if(document.all)
			{
				targetmenuObj.style.top = (ycoord + scrolltopdiff).toString() + 'px'; //(ycoord + this.offsetHeight-6 + scrolltopdiff).toString() + 'px';
			}
			else
			{
				targetmenuObj.style.top = (ycoord + scrolltopdiff).toString() + 'px'; //(ycoord + this.offsetHeight + scrolltopdiff).toString() + 'px';
			}
			//window.status = targetmenuObj.offsetParent;
			//targetmenuObj.style.top = (ycoord + this.offsetHeight-1 + scrolltopdiff).toString() + 'px';
			targetmenuObj.style.left = (xcoord + this.offsetWidth - scrolldiff).toString() + 'px'; //(xcoord - scrolldiff).toString() + 'px';
			targetmenuObj.style.visibility = "visible";
			targetmenuObj.onmouseover = function()
			{
				this.style.visibility = "visible";
				//window.status = this.offsetParent;
			}
			//alert(this.offsetTop + "   " + targetmenuObj.offsetTop + "    " + targetmenuObj.style.top + "   " + this.offsetHeight);
		}
		//alert(document.getElementById(targetdivID).id);	
		allspans[y].onmouseout = function()
		{
			
			targetmenuID = this.id.replace(/link/,"menu");
			
			targetmenuObj = document.getElementById(targetmenuID);
			//alert(this.id + "  " + targetmenuObj.id + "    " + this.offsetParent.tagName);
			var ycoord = this.offsetTop;
			var bodyObj = this;
			//while(bodyObj.tagName != "BODY")
			//{
				//bodyObj = bodyObj.offsetParent;
				//ycoord = ycoord+bodyObj.offsetTop;
			//	alert(bodyObj.offsetTop);
			//}
			
			//targetmenuObj.style.top = (ycoord).toString() + 'px';
			targetmenuObj.style.visibility = "hidden";
			targetmenuObj.onmouseout = function()
			{
				this.style.visibility = "hidden";
			}
		}
	}
}


