var mastertabvar=new Object()
mastertabvar.baseopacity=0
mastertabvar.browserdetect=""
var defaultID = ""

function showsubmenu(masterid, id)
{
	
	if (typeof highlighting!="undefined")
	clearInterval(highlighting)
	submenuobject=document.getElementById(id)
	mastertabvar.browserdetect=submenuobject.filters? "ie" : typeof submenuobject.style.MozOpacity=="string"? "mozilla" : ""
	hidesubmenus(mastertabvar[masterid])
	submenuobject.style.display="block"
	instantset(mastertabvar.baseopacity)
	highlighting=setInterval("gradualfade(submenuobject)",50)
	
	//debug("showing submenu masterid=" + masterid + "&id=" + id);
}

function hidesubmenus(submenuarray){
	for (var i=0; i<submenuarray.length; i++)
	document.getElementById(submenuarray[i]).style.display="none"
}

function instantset(degree)
{
	if (mastertabvar.browserdetect=="mozilla")
	submenuobject.style.MozOpacity=degree/100
	else if (mastertabvar.browserdetect=="ie")
		submenuobject.filters.alpha.opacity=degree
}


function gradualfade(cur2)
{
 if (mastertabvar.browserdetect=="mozilla" && cur2.style.MozOpacity<1)
	cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
	else if (mastertabvar.browserdetect=="ie" && cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10
		else if (typeof highlighting!="undefined") //fading animation over
			clearInterval(highlighting)
}

			function initalizetab(tabid)
			{				
				mastertabvar[tabid]=new Array()
				var menuitems=document.getElementById(tabid).getElementsByTagName("li")
				for (var i=0; i<menuitems.length; i++)
				{
					if (menuitems[i].getAttribute("rel"))
					{
						menuitems[i].setAttribute("rev", tabid) //associate this submenu with main tab
						mastertabvar[tabid][mastertabvar[tabid].length]=menuitems[i].getAttribute("rel") //store ids of submenus of tab menu
						if (menuitems[i].className=="selected")
						{							
							defaultID = menuitems[i].getAttribute("rel");
							showsubmenu(tabid, defaultID);							
							// when we return to the selected menu we want to 
							// stop the reset by clearing the timeout
							menuitems[i].onmouseover=function(){clearTimer();}							
						}
						else
						{
							// when we return to the selected menu we want to 
							// stop the reset by clearing the timeout
							menuitems[i].onmouseover=function(){clearTimer();}								
							
							// wireup onmouseout event to reset main menu to default selected 
							// menu will return to default selected
							menuitems[i].onmouseout=function(){TimedMenuReset();}
							
							// next set the submenu onmouseover event
							// we stop the reset by clearing the menuresettimeout
							var subMenuID = menuitems[i].getAttribute("rel");
//alert(subMenuID + '=' + document.getElementById(subMenuID));
							document.getElementById(subMenuID).onmouseover=function(){clearTimer();}
							
							// next we set the submenu onmouseout event to reset
							// however we need to avoid resetting the selected menu's items as this will 
							// cause an annoying flash of the already selected menu. so in short we disable
							// this for selected menu items.
							if (subMenuID != defaultID)
								document.getElementById(subMenuID).onmouseout=function(){TimedMenuReset();}					
																					
						}
						
						// show submenus when hovering over main manu items.
						menuitems[i].getElementsByTagName("a")[0].onmouseover=function()
						{
							//clearTimer();
							showsubmenu(this.parentNode.getAttribute("rev"), this.parentNode.getAttribute("rel"))								
							//alert(this.parentNode.id);
						}				
																
					}
				}
			}
			
function clearTimer()
{
	clearTimeout(timeHandler);	
}
		
var timeHandler;
function TimedMenuReset()
{			
  clearTimer();			  	
	timeHandler = setTimeout("ResetMenu()", 500);
}
		
function ResetMenu()
{
	//alert(defaultID)
	showsubmenu('maintab', defaultID);
}
		
	