var currentDiv = '';
var foMenuType = new Array();
var mOffset = 0; //-456;

// 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  alert(tEl.tagName + ':: ' + tEl.offsetLeft + ' :: ' + mPos); 
			mPos = tEl.offsetLeft;			
			while ((tEl = tEl.offsetParent).id != 'divMenuOverlay') { 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;   // removed offset height for RVR
		}		
	}
	
	return mPos;
}

function wrbsGetObjectOffset(sID, nMode)
{
	var mPos = 0;
	
	if (document.getElementById(sID))
	{
		var tEl = document.getElementById(sID);
		if (nMode == 1)
		{
			// find the position of the div  alert(tEl.tagName + ':: ' + tEl.offsetLeft + ' :: ' + mPos); 
			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;   // removed offset height for RVR
		}		
	}
	
	return mPos;
}

function wrbsShowMenu(sFODivID,sMenuItem,sMenuType,nExtraHeight)
{
	nExtraHeight = ((nExtraHeight)?nExtraHeight:0);
	var sParMenuID = sMenuItem.id;
	var lPos = wrbsGetMenuLocation(sParMenuID,1);
	lPos += mOffset;
	var tPos = wrbsGetMenuLocation(sParMenuID,2);
	tPos += nExtraHeight;

	// 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 wrbsPopWin(sUrl,sHeight,sWidth,bResize,bShowLoc)
{
	if (null == bResize) { bResize = true; }
	if (null == bShowLoc) { bShowLoc = true; }
	// correct for the scroll bars on the right
	sWidth = parseInt(sWidth)+20;
	
	var sScroll = 'yes';
	var bOpen = true;
	//alert(sUrl);
	
	switch (true)
	{
		case (sUrl.toLowerCase().indexOf('imap.ashx') > -1):
			sHeight='575';
			sWidth='775';
			sScroll = 'no';
			break;

		case (sUrl.toLowerCase().indexOf('http://rvrstore.myshopify.com/') > -1):
			bOpen = false;
			break;
	}
	
	if (bOpen)
	{
		var winProps = 'toolbar=no,scrollbars=' + sScroll + ',height=' + sHeight + ',width=' + sWidth + ((bResize)?',resizable=yes,resize=yes':'') + ((bShowLoc)?',location=yes':'');
		//alert(sUrl);
		var newWin = window.open(sUrl,'wrbsPop',winProps);
		newWin.focus();
	}
	else
	{
		document.location = sUrl;
	}
	
	return false;
}

