var currentDropdownId, currentDropdownMenuId, showDropdownDelay, hideDropdownDelay, currentDropdownHasCapture;
var showTimerId, hideTimerId;

//If the mouse move into the bucket but move out immediately, and the time it stayed
//in the bucket less than showDelay time, we don't want to show the dropdown.
//So this flag will be set true when mouse move in, and set false when move out
var stillShowDropdownAfterDelay = false;

showDelay=500;
hideDelay=1000;

function showDropdown(dropdownMenuId, show)
{
	var dropdownId;
	
	dropdownId=dropdownMenuId+"_sub";
	if (show)
	{
		stillShowDropdownAfterDelay = true;
		dropdown=document.getElementById(dropdownId);
		
		if (currentDropdownId && currentDropdownId!=dropdownId)
		{
			currentDropdown=document.getElementById(currentDropdownId);
			if (currentDropdown)
			{
				currentDropdown.style.display="none";
			}
			currentDropdownMenu=document.getElementById(currentDropdownMenuId);
			if (currentDropdownMenu)
			{				
				if (!isCurrentDivision(currentDropdownMenu)){
					currentDropdownMenu.className="";	
				}
				
			}
		}
		
		currentDropdownHasCapture=true;
		
		currentDropdownId=dropdownId;
		currentDropdownMenuId=dropdownMenuId;
		
		if (showTimerId)
		{
			clearTimeout(showTimerId);
		}
		if (dropdownMenuId)
		{
			//QC1359: by q04000
			//highlight the menu first, then show the dropdown after certain delay (half second)
			highlightDropdownMenu(true);
			showTimerId=setTimeout("showDropdownContainer('"+dropdownId+"', true)", showDelay);
		}
	}
	else
	{
		stillShowDropdownAfterDelay = false;
		currentDropdownHasCapture=false;
			
		highlightDropdownMenu(false);
		hideTimerId=setTimeout("showDropdownContainer('"+dropdownId+"', false)", hideDelay);
	}
}
function showDropdownContainer(dropdownId, show, forceHide)
{
	var dropdown, li;
	if (!show && currentDropdownHasCapture)
	{
		return;
	}
	
	dropdown=document.getElementById(dropdownId);
	if (dropdown)
	{
		if (show && stillShowDropdownAfterDelay )
		{
			dropdown.style.display="block";
			dropdown.style.zIndex=1000;
			if (dropdown.parentNode)
			{
				dropdown.parentNode.style.zIndex=1000;
			}
		} else {
			dropdown.style.display="none";
		}
	}
}

function highlightDropdownMenu( show )
{
	li=document.getElementById(currentDropdownMenuId);
	if (li && !isCurrentDivision(li))
	{
		li.className=show?"selected":"";
	}
}
function getDropdownCapture()
{
	currentDropdownHasCapture=true;
}

// INet changes: current division should always be selected 
// current divison is identified by class="current selected "

function isCurrentDivision (node){	
	return ((" "+node.className+" ").indexOf(" current ") >= 0); 
}
