var Tmr;

function showSubMenu(subMenuName,topMenuName)
{

	window.clearTimeout(Tmr);

	deselectAllTopExcept(topMenuName);
	hideAllSubExcept(subMenuName);
}

function hideSubMenu(subMenuName,topMenuName)
{
	subMenuNameString = ( subMenuName ) ? ( (subMenuName.id)?(subMenuName.id):(subMenuName) ) : ( 'notthere' );
	topMenuNameString = ( topMenuName ) ? ( (topMenuName.id)?(topMenuName.id):(topMenuName) ) : ( 'notthere' );
	
	if( subMenuNameString != 'notthere' )
		Tmr = setTimeout("hideSubMenuTimed('" + subMenuNameString + "','" + topMenuNameString + "')",500);
	else
		Tmr = setTimeout("hideSubMenuTimed(null,'" + topMenuNameString + "')",500);
}

function hideSubMenuTimed(smName,tmName)
{
	smNameString = ( smName ) ? ( (smName.id)?(smName.id):(smName) ) : ( 'notthere' );
	tmNameString = ( tmName ) ? ( (tmName.id)?(tmName.id):(tmName) ) : ( 'notthere' );
	
	 if( document.getElementById( smNameString ) && smNameString != 'notthere' )
	 	document.getElementById( smNameString ).style.visibility="hidden";

	 if( document.getElementById( tmNameString ) )
		document.getElementById( tmNameString ).style.background="#4683b5";
}

function hideAllSubExcept(showThisSubID)
{
	var allSubs = getElementsByClassName("subMenu");
	var curSub;
	
	showThisSubIDString = ( showThisSubID ) ? ( (showThisSubID.id)?(showThisSubID.id):(showThisSubID) ) : ('notthere');

	if( document.getElementById( showThisSubIDString ) && showThisSubIDString != 'notthere' )
		curSub = document.getElementById(showThisSubIDString);
	else
		curSub = null;

	for(var i = 0; i < allSubs.length; i++)
	{
		if( allSubs[i] == curSub )	//identify the sub that is to be shown VS hidden
		{
			curSub.style.visibility="visible";
			curSub.style.zIndex="99";
		}
		else	//hide all other sub menus
		{
			allSubs[i].style.visibility="hidden";
			allSubs[i].style.zIndex="0";
		}
	}

}

function deselectAllTopExcept(selectThisTopID)
{
	selectThisTopIDString = ( selectThisTopID ) ? ( (selectThisTopID.id)?(selectThisTopID.id):(selectThisTopID) ) : ('notthere');

	var allTops = getElementsByClassName("topMenu");
	var curTop = document.getElementById(selectThisTopIDString);

	for(var i=0;i<allTops.length;i++)
	{
		if( allTops[i] == curTop )
			curTop.style.background="#ff9900";
		else
			allTops[i].style.background="#4683b5";
	}

}

function getElementsByClassName(cl)
{
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = document.getElementsByTagName("*");

	for (var i = 0; i < elem.length; i++)
	{
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}

