var tn_expanded = null;	// currently expanded menu
var tn_canClose = true;
var tn_timeOutId = -1;

function topnav(img)
{
	var menu = tn_getMenu(img);

	if(menu != null && menu == tn_expanded)
	{
		return;
	}
	
	tn_doCollapse(true);
	
	if(menu != null)
	{
		tn_expanded	= menu;
	
		menu.style.position	= 'absolute';
		menu.style.left		= img.offsetLeft + 'px';
		menu.style.top		= img.offsetTop + (document.all ? img.parentNode.offsetTop : 0) + 'px';
		menu.style.zIndex	= 200;
		menu.onmouseout		= tn_collapse;
		
		tn_showHide(menu, true);
		return;
	}
	
	if(img.src.indexOf('a_on') == -1)
	{
		img.src = img.src.replace('_off.gif', 'a_on.gif');
		img.onmouseout = function() { this.src = this.src.replace('a_on.gif', '_off.gif'); }
	}
}

function tn_getMenu(img)
{
	return document.getElementById(img.id + '-menu');
}

function tn_showHide(obj, show)
{
	obj.style.visibility = show ? 'visible' : 'hidden';
}

function tn_collapse()
{
	tn_canClose = true;
	clearInterval(tn_timeOutId);
	tn_timeOutId = setTimeout('tn_doCollapse()', 1000);
}

function tn_doCollapse(force)
{
	clearInterval(tn_timeOutId);
	
	if(!tn_canClose && !force)
	{
		return;
	}
	
	if(tn_expanded != null)
	{
		tn_showHide(tn_expanded, false);
		tn_expanded = null;
	}
}

function tn_keep(sender)
{
	tn_canClose = false;
	sender.onmouseout = tn_collapse;
}

