var selectedPrimary = '';
var selectedSecondaryContainer = '';

var hoverPrimary = '';
var hoverSecondaryContainer = '';

var menuTimer;

function showmenu(element) {
	
	var element = String(element.id);
	//alert(typeof(element));
	// move to hidemenu when appropriate
	selectedPrimary = element;
	selectedSecondaryContainer = element + "_secondary";
	
	if (hoverPrimary != '') {
		off_assignment(document.getElementById(hoverPrimary));
		off_assignment(document.getElementById(selectedPrimary));
		
		document.getElementById(hoverSecondaryContainer).style.display = "none";
		document.getElementById(selectedSecondaryContainer).style.display = "block";
	}
	hoverPrimary = element;
	hoverSecondaryContainer = element+"_secondary";
	flip_assignment(document.getElementById(selectedPrimary));
	//element.className = element.className.replace("_on", "");

	var previous = document.getElementById(selectedSecondaryContainer);
	previous.style.display = "none";

	document.getElementById(hoverSecondaryContainer).style.display = "block";
	if (hoverSecondaryContainer != selectedSecondaryContainer)
		document.getElementById(selectedSecondaryContainer).style.display = "none";
}

function start_menu_timeout() {
	if ((hoverPrimary != selectedPrimary) && (menuTimer == null))
		menuTimer = setTimeout("reset_menu()", 1000);
}

function cancel_menu_timeout() {
	if ((hoverPrimary != selectedPrimary) && (menuTimer != null)) {
		clearTimeout(menuTimer);
		menuTimer = null;
	}
}

function reset_menu() {
	if (hoverPrimary != selectedPrimary) {
		document.getElementById(hoverSecondaryContainer).style.display = "none";
		document.getElementById(selectedSecondaryContainer).style.display = "block";

		flip_assignment(document.getElementById(selectedPrimary));
		flip_assignment(document.getElementById(hoverPrimary));
	}
}

function flip_assignment(element) {
	if (element.className.indexOf('p7TBMon') !=-1) {
		//element.className = element.className.replace("_on", "");
		element.className = "";
	} else {
		//element.className = element.className + "_on";
		element.className = "p7TBMon";
	}
}

function off_assignment(element) {
	//element.className = element.className.replace("_on", "");
	element.className = "";
}

var p7tbma=new Array();
var p7tbmt=new Array();
var inOutCount = 0;
var defaultTab;

function init_nav()
{
//define over and down image suffix
var Iv = "_f2";
var Id = "_f3";
var i,j,x,k,d,nV,tB,tbs,iM,im,ts,tA,sA,sL,nA=new Array();

//Get the active tab/submenu item
var urlParts = window.location.href.split(/\/+/);
var urlTabName, tabId, tabUrlParts, tabName;
if ((urlParts.length > 2) && (urlParts[2] != '')) {
	urlTabName = urlParts[2];
}
document.p7tbmsw=new Array();
p7tbma=arguments;
if(!document.getElementById||document.p7tbmf){return;}
tb=document.getElementById('p7TBM');
if(!tb){return;}
//tb.onmouseout=P7_TBMclose;	//*
tB=document.getElementById('p7TBM');
nV=document.getElementById('p7TBMroot');
if(!nV||!tB){return;}
tA=nV.getElementsByTagName('A');
j=0;

//Get the active submenu item and set the onmouse event for every submenu item
//This loops through all the link tags in the top-level nav
for(i=0;i<tA.length;i++)
{
	//alert(tA[i]);
	if ((urlTabName) && (!defaultTab)) {
		tabUrlParts = tA[i].href.split(/\/+/);
		if ((tabUrlParts[0].match(/http:/i)) && (tabUrlParts[1] != 'www.denverpost.com') && (tabUrlParts[1] != 'preview.denverpost.com') && (tabUrlParts[2] == '')) {
			tabName = tA[i].href;
		} else if (tabUrlParts.length == 1) {
			tabName = tabUrlParts[0];
		} else if (tabUrlParts[0] == '') {
			tabName = tabUrlParts[1];
		} else if (tabUrlParts.length > 2) {
			tabName = tabUrlParts[2];
		}

		if ((tA[i].href == window.location.href) || (tabName == urlTabName)) {
			defaultTab = tA[i];
		}
	}
	p7tbmt[j]=tA[i].id;
	j++;
	d='p7TBMsub'+tA[i].id.replace('p7TBMt','');
	tabId = tA[i].id.replace('p7TBMt','');
	tbs=document.getElementById(d);
	//tbs.onmouseover=function(){P7_TBMsub(this);};
	if ((tbs) && (tabId != '01')) {
		sA = tbs.getElementsByTagName('A');
		var ii,linkName;
		if (sA) {
			//This loops through all the link tags in the subnavs
			for (ii=0;ii<sA.length;ii++) {
				//alert(sA[ii]);
				var subUrlParts = sA[ii].href.split(/\/+/);
				var subName = '';
				if ((subUrlParts[0].match(/http:/i)) && (subUrlParts[1] != 'www.denverpost.com') && (subUrlParts[1] != 'preview.denverpost.com') && (subUrlParts[1] != 'www.politicswest.com') && (subUrlParts[2] == '')) {
					subName = sA[ii].href;
				} else if (subUrlParts.length == 1) {
					subName = subUrlParts[0];
				} else if (subUrlParts[0] == '') {
					subName = subUrlParts[1];
				} else if (subUrlParts.length > 2) {
					subName = subUrlParts[2];
				}
				if ((subName == window.location.href) || (subName == urlTabName)){
					defaultTab = tA[i];
					if (sA[ii].parentNode.className == '') {
						sA[ii].parentNode.className = 'selectedItem';
					} else {
						sA[ii].parentNode.className = sA[ii].parentNode.className + ' selectedItem';
					}
					ii = sA.length;
				}
			}
		}
	}
	p7tbmt[j]=(tbs)?tbs.id:false;
	tA[i].hasSub=p7tbmt[j];
	j++;
	tA[i].isRoot=true;
	//tA[i].onclick=function(){return P7_TBMtrig(this);};
	//tA[i].onmouseover=function(){P7_TBMovr(this);};
	tA[i].p7state=0;
	tA[i].hasIm=false;
	iM=tA[i].getElementsByTagName('IMG');
	if(iM&&iM[0]){
		im=iM[0];
		ts=im.getAttribute("src");
		x=ts.lastIndexOf(".");
		nA[0]=ts.substring(0,x);
		nA[1]='.'+ts.substring(x+1);
		im.p7mimg=new Array();
		im.p7mimg[0]=ts;
		if(p7tbma[1]>1){
			ts=nA[0]+Iv+nA[1];
			P7_TBMpl(ts);
		}
		im.p7mimg[1]=ts;
		if(p7tbma[1]==3){im.p7mimg[2]=ts;}
		if(p7tbma[1]==1||p7tbma[1]==2){
			ts=nA[0]+Id+nA[1];
			P7_TBMpl(ts);
			if(p7tbma[1]==1){im.p7mimg[1]=ts;}
		}
		im.p7mimg[2]=ts;
		im.p7state=0;
		tA[i].hasIm=true;
	}
}
//document.p7tbmf=true;P7_TBMopen();

//If the current page does not match a tab then show home
if (!defaultTab) {defaultTab = 'nav_home';}
else 
{
	//If we have a value for defaultTab, we will need to parse out the right bit so we can pass it to the display function
	var mydefaultTab = String(defaultTab);
	var mytabParts = mydefaultTab.split("/");
	var tabPartsLength = mytabParts.length - 1;
	var defaultTab = "nav_" + mytabParts[tabPartsLength];
}

//var navContainer = document.getElementById('navcontainer');
//navContainer.onmouseout=P7_TBMallout
//Select the current tab
//if ( defaultTab == undefined ) showmenu(document.getElementById('nav_politics'));
//else showmenu(document.getElementById(defaultTab));
showmenu(document.getElementById(defaultTab));
}

