var currentDiv = '';
var foMenuType = new Array();
var mOffset = 20;

// variable to determine the navigator
var isNS = (navigator.appName.toLowerCase().indexOf('netscape') > -1);

/*
doFixNews()
This function adds a few extra line breaks to the marquee scroller in Netscape
*/
function doFixNews()
{
	if (isNS && document.getElementById('marqNews'))
	{
		document.getElementById('marqNews').innerHTML = '<br><br>' + document.getElementById('marqNews').innerHTML;
	}
}

/*
sID = the id of the menu div
sMode = [1=left pos|2=top pos]
*/
function wrbsGetMenuLocation(sID, nMode)
{
	var mPos = 0;
	
	if (document.getElementById(sID))
	{
		var tEl = document.getElementById(sID);
		if (nMode == 1)
		{
			// find the position of the div
			mPos = tEl.offsetLeft;			
			while ((tEl = tEl.offsetParent) != null) { mPos += tEl.offsetLeft; }
		}
		else if (nMode == 2)
		{
			// find the position of the div
			mPos = tEl.offsetTop;			
			while ((tEl = tEl.offsetParent) != null) { mPos += tEl.offsetTop; }
			tEl = document.getElementById(sID);
			mPos += tEl.offsetHeight;
		}		
	}
	
	return mPos;
}

function getOffsetLeft(sID)
{
	var tEl = document.getElementById(sID);
	mPos = tEl.offsetLeft;			
	while ((tEl = tEl.offsetParent) != null) { mPos += tEl.offsetLeft; }
	
	return mPos;	
}

function getOffsetTop(sID)
{
	var tEl = document.getElementById(sID);
	mPos = tEl.offsetTop;			
	while ((tEl = tEl.offsetParent) != null) { mPos += tEl.offsetTop; }
	tEl = document.getElementById(sID);	
	
	return mPos;
}

function wrbsShowMenu(sFODivID,sMenuItem,sMenuType)
{
	var sParMenuID = sMenuItem.id;
	var lPos = wrbsGetMenuLocation(sParMenuID,1);
	lPos += mOffset;
	var tPos = wrbsGetMenuLocation(sParMenuID,2);
	
	// if this is a vertical menu, correct the location of the flyout
	if (sMenuType == 'vertical') 
	{ 
		lPos += sMenuItem.offsetWidth; 
		tPos -= sMenuItem.offsetHeight;
	}
	//alert(tPos+', '+lPos);
	
	wrbsCloseAllFO();

	var foMenu = document.getElementById(sFODivID);
	foMenu.style.top = tPos+'px';
	foMenu.style.left = lPos+'px';
	//alert(tPos + ': '+lPos);
	foMenu.style.display = 'inline';
	
	sMenuItem.onmouseout = wrbsSetCloseTime;
	foMenu.onmouseover = wrbsClearTimer;
	foMenu.onmouseout = wrbsSetCloseTime;
}

var sTimer = '';

function wrbsClearTimer()
{
	clearTimeout(sTimer);
}


function wrbsSetCloseTime()
{
	sTimer = setTimeout('wrbsCloseAllFO();',500);
}


function wrbsCloseAllFO()
{
	var oDiv = document.getElementsByTagName('DIV');
	var x = 0;
	
	for (x=0; x<oDiv.length; x++)
	{
		if (oDiv[x].id.indexOf('fo_sm_') > -1)
		{
			oDiv[x].style.display = 'none';
		}
		
	}
	//wrbsClearTimer();
	clearTimeout(sTimer);
}

function getUTCStamp()
{
	var d = new Date();
	var retVal = Date.UTC(d.getYear(),d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());	
	
	return retVal;
}

function wrbsPopWin(sUrl,sHeight,sWidth,bResize,bShowLoc,bForceNew)
{
	sHeight = 580; //(!sHeight || sHeight == 'undefined') ? 400 : sHeight;
	sWidth= 720; //(!sWidth|| sWidth == 'undefined') ? 400 : sWidth;

	if (sUrl.toLowerCase().indexOf('http://') == 0 || sUrl.toLowerCase().indexOf('https://') == 0 || bForceNew)
	{
		if (null == bResize) { bResize = true; }
		if (null == bShowLoc) { bShowLoc = true; }
		// correct for the scroll bars on the right
		sWidth = parseInt(sWidth)+20;
		
		var winProps = 'toolbar=no,scrollbars=yes,height=' + sHeight + ',width=' + sWidth + ((bResize)?',resizable=yes,resize=yes':'') + ((bShowLoc)?',location=yes':'');
		//alert(sUrl.toLowerCase().indexOf('/liveplayer/player.aspx'));
		if (sUrl.toLowerCase().indexOf('/liveplayer/player.html') > -1 || sUrl.toLowerCase().indexOf('/liveplayer/player.aspx') > -1)
		{
			//alert(document.location.url);
			//alert(getUTCStamp());
			sUrl += ((sUrl.indexOf('?') > -1)?'&':'?') + 'tstamp=' + getUTCStamp();
			var playerWin = window.open(sUrl,'playerPop',winProps);
			playerWin.focus();
		}
		else
		{
			var newWin = window.open(sUrl,'popWin',winProps);
			newWin.focus();
		}
	}
	else
	{
		document.location.href = sUrl;
	}
	
	return false;
}
