var m_HideSpNavBarSubTID;
var m_NavBarAjaxCache = new Object();
var m_NavBarAjaxRequestPending = "RequestPending";

YAHOO.namespace("container");

function YAHOOinitSpNavBarSub() {
	YAHOO.container.SpNavBarSub = 
		new YAHOO.widget.Panel("SpNavBarSub", { visible:false,
			iframe:false,
			constraintoviewport:true,
			close:false,
			draggable:false,
			modal:false,
			underlay:'shadow',
			width:'220px',
			zIndex:'11'
		} );

	YAHOO.container.SpNavBarSub.render();
	
	//wire-up ui event handlers for show/hide
	var SpNavBarSub = document.getElementById('SpNavBarSub');
	SpNavBarSub.onmouseover = function(){ clearTimeout(m_HideSpNavBarSubTID); };
	SpNavBarSub.onmouseout = function(){ HideSpNavBarSub(); };
}

YAHOO.util.Event.onDOMReady(YAHOOinitSpNavBarSub);

function ShowSpNavBarSub(contextId, contentId)
{
	clearTimeout(m_HideSpNavBarSubTID);
	
	var containerBd = document.getElementById('SpNavBarSubBody');
	containerBd.innerHTML = document.getElementById(contentId).innerHTML;
	
	YAHOO.container.SpNavBarSub.cfg.setProperty('context', [contextId,'tl','bl']);
    YAHOO.container.SpNavBarSub.cfg.setProperty('width', '220px');
	
	//IE hack: underlay size does not change with panel size; resize it now
	if(document.all) YAHOO.container.SpNavBarSub.sizeUnderlay();
	
	YAHOO.container.SpNavBarSub.show();
	return false;
}

function ShowSpNavBarSubVarWidth(contextId, contentId, width)
{
	clearTimeout(m_HideSpNavBarSubTID);
	
	var containerBd = document.getElementById('SpNavBarSubBody');
	containerBd.innerHTML = document.getElementById(contentId).innerHTML;
	
	YAHOO.container.SpNavBarSub.cfg.setProperty('context', [contextId,'tl','bl']);
    YAHOO.container.SpNavBarSub.cfg.setProperty('width', width);
	
	//IE hack: underlay size does not change with panel size; resize it now
	if(document.all) YAHOO.container.SpNavBarSub.sizeUnderlay();
	
	YAHOO.container.SpNavBarSub.show();
	return false;
}


function ShowSpNavBarSubAjax(contextId, contentUrl, prependContainerId)
{
	clearTimeout(m_HideSpNavBarSubTID);

	// check to see if the url exists in the cache
	var Data = m_NavBarAjaxCache[contentUrl]

	if (Data != undefined) {
		// request pending = let the original callback handle the request
		if (Data == m_NavBarAjaxRequestPending) return false;

		ShowSpNavBarSubAjaxCallback(contextId, contentUrl, Data, prependContainerId);
		return false;
	}

	// ok, let's tell the cache we're pending
	m_NavBarAjaxCache[contentUrl] = m_NavBarAjaxRequestPending;

	var CacheBuster;

	if (contentUrl.indexOf('?') >= 0)
		CacheBuster = '&ts=';
	else
		CacheBuster = '?ts=';

	CacheBuster += (new Date()).getTime();

	$.get(contentUrl + CacheBuster, function(data) {
		ShowSpNavBarSubAjaxCallback(contextId, contentUrl, data, prependContainerId);
	});

	return false;
}

function ShowSpNavBarSubAjaxCallback(contextId, contentUrl, data, prependContainerId) {
	m_NavBarAjaxCache[contentUrl] = data;

	var containerBd = document.getElementById('SpNavBarSubBody');
	var PrependData;
	var FinalContent = '';

	if (prependContainerId) {
		PrependData = document.getElementById(prependContainerId).innerHTML;
	}

	if (PrependData)
		FinalContent += PrependData;

	if (PrependData && data) {
		FinalContent += '<div id="MoreMenuCustomPages">';
		FinalContent += data;
		FinalContent += '</div>';
	} else if (data) {
		FinalContent += data;
	}

	containerBd.innerHTML = FinalContent;

	YAHOO.container.SpNavBarSub.cfg.setProperty('context', [contextId,'tl','bl']);
	    YAHOO.container.SpNavBarSub.cfg.setProperty('width', '220px');

	//IE hack: underlay size does not change with panel size; resize it now
	if(document.all) YAHOO.container.SpNavBarSub.sizeUnderlay();

	YAHOO.container.SpNavBarSub.show();
}

function HideSpNavBarSub()
{
	m_HideSpNavBarSubTID = setTimeout('YAHOO.container.SpNavBarSub.hide();',700);
}

