// this var is used to track which tab is currently visible
var tabup = 0;
var selectedtab = "tabAllSections";

if (is.ns) {
	document.tab1.captureEvents(Event.MOUSEOVER);
	document.tab1.onmouseover = blah;	
}

function blah() {
	alert("blah");
}

// cross browser DOM translation... use this to reference layers/divs
function getObj(name) {	

	if (document.getElementById) {
		if (document.getElementById(name)) {
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		}		
	} else if (document.all) {
		if (document.all[name]) {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		}
	} else if (document.layers) {
		this.obj = getObjNN4(document,name);
		this.style = this.obj;
	}
}

// get NN4 layer (used by function above)
function getObjNN4(obj,name) {
	var x = obj.layers;
	var thereturn;
	for (var i=0;i<x.length;i++) {
		if (x[i].id == name) {
		 	thereturn = x[i];
		} else if (x[i].layers.length) {
			var tmp = getObjNN4(x[i],name);
		}
		if (tmp) thereturn = tmp;
	}
	return thereturn;
}

function trace(text) {
	/*
	txtDebug = new getObj("traceBox");
	if (txtDebug) {
		txtDebug.value += text + "\n";
	}
	return false;
	*/
}

function showFilters () {
	var x = new getObj("filterOptions");
	x.style.visibility = 'visible';
}

function hideFilters () 
{
	var x = new getObj("filterOptions");
	x.style.visibility = 'hidden';
}

function rolloverTab(tabID) 
{
	closeTabs();

	if (tabID == 'tabAllSections') {
	
		var tabObj = new getObj("tabAllSections");
		tabObj.obj.className = "tabhover";
	
	} else {
	
	
		// set current tab number
		tabup = tabID;	

		var tabObj = new getObj("tab"+tabID);
		var popObj = new getObj("popup"+tabID);
		
		// set style of tab
		//tabObj.obj.className = "tabhover";
				
		// trace("tabObj.obj.className = " + tabObj.obj.className);

		// position popup menu div		
		if (document.all) 
		{			
		
			var xpos = document.body.scrollLeft + event.clientX - event.offsetX - 4;
			var ypos = document.body.scrollTop  + event.clientY - event.offsetY + tabObj.obj.clientHeight;		
			if (xpos > (document.body.offsetWidth - 200)) {
				// alert("blah");
				xpos = document.body.offsetWidth - 200;
			}
			//alert(xpos + " : " + document.body.offsetWidth);
		} 
		else if (document.layers) 
		{
			var xpos = tabObj.obj.pageX - tabObj.obj.layerX;
			var ypos = tabObj.obj.pageY - tabObj.obj.layerY + 19;
		}
		
		popObj.style.left = xpos;
		popObj.style.top  = ypos;
			
		popObj.style.visibility = 'visible';	
		
		hideFilters();
		setTimeout("closeTab(" + tabID + ")", 1000);
	}
	
//alert("selectedtab:" + selectedtab);

}

function rolloverMenu(tabID) 
{
	var tabObj = new getObj("tab"+tabID);
	var popObj = new getObj("popup"+tabID);
	
	tabup = tabID;
	tabObj.obj.className = 'tabhover';
	popObj.style.visibility = 'visible';	
	
	hideFilters();
	setTimeout("closeTab("+tabID+")", 1000);
}

function rolloffTab(tabID) 
{	
	if (tabID == 'tabAllSections') 
	{	
		var tabObj = new getObj("tabAllSections");
		tabObj.obj.className = "tabup";	
	} 
	else 
	{		
		tabup = 0;
		setTimeout("closeTab("+tabID+")", 100);
		closeTabs();
	}
}

function closeTabs() 
{
	if (!tabup) 
	{
		for (i=1;i<=4;i++)
		{
			var tabObj = new getObj("tab"+i);
			var popObj = new getObj("popup"+i);	
			if (tabObj.obj) 
			{
				tabObj.obj.className = 'tabup';
				popObj.style.visibility = 'hidden';
			}
		}					
	}
	// restore selected tab
	//var tabObj = new getObj(selectedtab);
	//tabObj.obj.className = "tabdown";
}

function closeTab(tabID) 
{
	var tabObj = new getObj("tab"+tabID);
	var popObj = new getObj("popup"+tabID);
	
	if (tabup != tabID) 
	{
		if (selectedtab == "tab" + tabID)
		{
			tabObj.obj.className = 'tabdown';
		}
		else
		{
			tabObj.obj.className = 'tabup';
		}
		popObj.style.visibility = 'hidden';		
	}
	if (!tabup) 
	{
		closeTabs();
		showFilters();
	}
}