var	arrTBMenu = new Array(null, null, null);
var	hideTBTimer = null;
var hideTBTimerInterval = 500;

var m_tb_isIE			= (window.navigator.appName == "Microsoft Internet Explorer");
var m_tb_isNetscape		= (window.navigator.appName == "Netscape");
var m_tb_isOpera		= (window.navigator.userAgent.indexOf("Opera") > -1);
var m_tb_isSafari		= (window.navigator.userAgent.indexOf("Safari") > -1);
var m_tb_showTb			= true;

m_tb_showTb = !(m_tb_isNetscape && m_tb_isOpera);

if (!m_tb_isIE && !m_tb_isNetscape && !m_tb_isOpera && !m_tb_isSafari)
	m_tb_showTb = false;

function funcDefaultBrowserVersion()
{
      var ua = window.navigator.userAgent;
      var msie = ua.indexOf ( "MSIE " )
      if ( msie > 0 )      // If Internet Explorer, return version number
         return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
      else                 // If another browser, return 0
         return 0
}

function funcTBDefaultBrowserVersionAsFloat()
{
      var ua = window.navigator.userAgent;
      var msie = ua.indexOf ( "MSIE " )
      if ( msie > 0 )      // If Internet Explorer, return version number
         return parseFloat (ua.substring (msie+5, ua.indexOf (".", msie ) + 2))
      else                 // If another browser, return 0
         return 0
}


function CalculateToolbarX( eventObj )
{ 
	nX = 0;
	var objTag = eventObj;
	while( objTag.tagName != "BODY" )
	{
		// alert(objTag.offsetLeft + ": " + objTag.tagName + ": " + objTag.id);
		if( objTag.tagName == "DIV" && m_tb_isNetscape) // netscape and opera
			break;
		nX += objTag.offsetLeft;
		if( objTag.id == "mainNavigation" && m_tb_isOpera) // netscape and opera
			break;
		objTag = objTag.parentNode;
	}
	if (m_tb_isOpera)
	{
		nX += 3;
	}
	return nX;
}

function CalculateToolbarY( eventObj )
{ 
	nY = eventObj.offsetHeight;
	var objTag = eventObj;
	while( objTag.tagName != "BODY" )
	{
		// alert(objTag.offsetTop + ": " + objTag.tagName);
		if( objTag.tagName == "DIV" && m_tb_isNetscape) // netscape and opera
			break;
		nY += objTag.offsetTop;
		if( objTag.tagName == "DIV" && objTag.offsetTop > 0 && m_tb_isOpera) // netscape and opera
			break;
		objTag = objTag.parentNode; 
	}
	return nY;
}


function funcShowToolbarDropdown(eventObj, layerId)
{
	if (!document.getElementById || !m_tb_showTb)
		return;

	if (arrTBMenu[0] != null)
	{
	    if (eventObj != arrTBMenu[0])
	    {
	        hideToolbarMenusTo(eventObj);
	        if (funcTBDefaultBrowserVersionAsFloat() == 5) //ie 5 bug
				return;
	    }
	}
	stopToolbarHideTimer();
	if (funcTBDefaultBrowserVersionAsFloat() != 5) //ie 5 bug
	{
		if (eventObj.className.indexOf("login") == 0)
			eventObj.className		= "loginHover";
		else
			eventObj.className		= "defaultHover";
	}
	/*else // ie 5 bug
		eventObj.style.backgroundColor	= "#e5eaef";*/
	var obj					= document.getElementById(layerId);
	var objFill				= document.getElementById("lidFillDropdown");
	if (obj != null && objFill != null)
	{
		funcToogleDropdowns("hidden");
		arrTBMenu[0]	= eventObj;
		arrTBMenu[1]	= obj;
		arrTBMenu[2]	= objFill;
		intX = CalculateToolbarX(eventObj);
		intY = CalculateToolbarY(eventObj);
		
		if (funcTBDefaultBrowserVersionAsFloat() == 5) //ie 5 bug
			intY		+= 6;
		if (m_tb_isSafari)
			intY		+= 5;
		var eventObjOffsetWidth		= eventObj.offsetWidth - 2;
		if (m_tb_isOpera)
		{
			eventObjOffsetWidth		-= 4;
			intX					-= 3;
		}
			
		obj.style.visibility		= "hidden";
		obj.style.left = -5000;
		obj.style.top = 0;
		obj.style.display = 'block';
		
		// check for window overflow
		
		obj.style.left = intX + "px";
		obj.style.top = intY + "px";
		obj.style.zIndex = 100;
		obj.style.visibility	= "visible";
	    if (funcTBDefaultBrowserVersionAsFloat() != 5)	// ie 5 bug
		    objFill.style.display = 'block';
		else
			objFill.style.display = 'none';    
		
		objFill.style.left = intX + "px";
		objFill.style.top = (intY - 6) + "px";
		objFill.style.width = eventObjOffsetWidth + "px";
		objFill.style.zIndex = 1000;
		objFill.style.visibility	= "visible";
	}
}

function funcToogleDropdowns(sVisibility)
{
	var ieVersion	= funcDefaultBrowserVersion();
	if (ieVersion > 4 && ieVersion < 7)
	{
		if (document.getElementsByTagName)
		{
			if (document.getElementById("relatedContent") != null)
			{
				for (var i = 0; i < document.getElementById("relatedContent").getElementsByTagName("select").length; i++)
				{
					document.getElementById("relatedContent").getElementsByTagName("select")[i].style.visibility	= sVisibility;
				}
			}
		}
	}
}

function hideToolbarMenusTo(eventObjId)
{
	if (arrTBMenu[0] != null)
	{
		if (funcTBDefaultBrowserVersionAsFloat() != 5)
		{
			if (arrTBMenu[0].className.indexOf("login") == 0)
				arrTBMenu[0].className		= "login";
			else
				arrTBMenu[0].className		= "default";
		}
		else // ie 5 bug
		{
			arrTBMenu[0].style.backgroundColor	= "";
			arrTBMenu[0] = null;
		}
		
		funcToogleDropdowns("visible");
	}

	if (arrTBMenu[1] != null)
		arrTBMenu[1].style.display	= "none";
	if (arrTBMenu[2] != null)
		arrTBMenu[2].style.display	= "none";
}

function startToolbarHideTimer(eventObj)
{
	stopToolbarHideTimer();
	var strTimeout = 'hideToolbarMenusTo(\'' + eventObj.id + '\')';
	hideTBTimer = setTimeout(strTimeout, hideTBTimerInterval);
}

function stopToolbarHideTimer()
{
	if (hideTBTimer) 
		clearTimeout(hideTBTimer);
	hideTBTimer = null;
}
