// JavaScript Document

var numOfTabs = 5;

////////////////////////////////////////////////
// PRIVATE FUNCTIONS
////////////////////////////////////////////////


function clearSecondaryLinkSelections() {
	for (i=0; i<document.getElementById('secondaryLinks').childNodes.length; i++) {
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
			var ieversion=new Number(RegExp.$1)
			if (ieversion<8) {}//document.getElementById('secondaryLinks').childNodes.item[i].border = "0";
			else {} //document.getElementById('secondaryLinks').childNodes.item[i].border = "0";
		} else {
			document.getElementById('secondaryLinks').childNodes.item(i).border = "0";
		} // else
	} // for
} // function clearSecondaryLinkSelections


function highlightNewSecondaryLink(whichLink) {
	document.getElementById(whichLink).style.borderBottom = "2px dotted orange";
} // function highlightNewSecondaryLink


function clearTabSelections() {
	var allTabs = document.getElementById('tabContainer').childNodes;
	for (i=0; i<numOfTabs; i++) {
		document.getElementById('innerNavbarContent_' + i).style.display = 'none';
		document.getElementById('tabitem_' + i).style.backgroundColor = 'transparent';
		document.getElementById('tabitem_' + i).style.color = '#444';
		document.getElementById('tabitem_' + i).style.backgroundImage = 'url(images/tab_pipe.jpg)';
		document.getElementById('tabitem_' + i).onmouseover = function() { this.style.color = "#999"; }
		document.getElementById('tabitem_' + i).onmouseout = function() { this.style.color = "#444"; }
	} // for
} // function clearTabSelections


function selectNewTabAndShowNewNavbar(whichTab) {
	document.getElementById('innerNavbarContent_' + whichTab).style.display = 'block';
	document.getElementById('tabitem_' + whichTab).style.backgroundColor = '#a96a00';
	document.getElementById('tabitem_' + whichTab).style.color = '#FFF';
	document.getElementById('tabitem_' + whichTab).onmouseover = function() {  }
	document.getElementById('tabitem_' + whichTab).onmouseout = function() {  }
	document.getElementById('tabitem_' + whichTab).style.backgroundImage = 'none';
	if (whichTab > 0) {
		document.getElementById('tabitem_' + (whichTab-1)).style.backgroundImage = 'none';
	} // if
} // function selectNewTabAndShowNewNavbar


function removePipeFromLastTab() {
	document.getElementById('tabitem_' + (numOfTabs-1)).style.backgroundImage = 'none';
} // function removePipeFromLastTab


function getNumberIdOfTab(whichLink) {
	fullIdOfTab = document.getElementById(whichLink).parentNode.parentNode.id;
	fullIdOfTab_array = fullIdOfTab.split('_');
	numberIdOfTab = fullIdOfTab_array[fullIdOfTab_array.length-1];
	return numberIdOfTab;
} // function getNumberIdOfTab


function selectNewNavbarLink(whichLink) {
	document.getElementById(whichLink).style.backgroundImage = "url(images/selected_tab_bg.jpg)";
	document.getElementById(whichLink).style.paddingTop = "3px";
	document.getElementById(whichLink).firstChild.style.color = "#222";
	document.getElementById(whichLink).onmouseover = function() {  }
	document.getElementById(whichLink).firstChild.onmouseover = function() {  }
	document.getElementById(whichLink).firstChild.style.cursor = 'default';
	document.getElementById(whichLink).onmouseout = function() {  }
	document.getElementById(whichLink).firstChild.onmouseout = function() {  }
} // function selectNewNavbarLink



////////////////////////////////////////////////
// PUBLIC FUNCTIONS
////////////////////////////////////////////////

// The function must be manually called on a page that is listed in the secondary links
function selectSecondaryLink(whichLink) {
	clearSecondaryLinkSelections();
	clearTabSelections();
	removePipeFromLastTab();
	highlightNewSecondaryLink(whichLink);
} // function selectSecondaryLink


// This function is called when a new tab is clicked on or manually on a page that is listed someowhere in a navbar of a tab
function changeTabAndNavbar(whichTab) {
	clearTabSelections();
	removePipeFromLastTab();
	selectNewTabAndShowNewNavbar(whichTab);
} // function showNavbar


// this funtion is called when a page is loaded by clicking on a navbar link
function selectNavbarLink(whichLink) {
	clearSecondaryLinkSelections();
	clearTabSelections();
	removePipeFromLastTab();
	numberIdOfTab = getNumberIdOfTab(whichLink);
	selectNewTabAndShowNewNavbar(numberIdOfTab);
	selectNewNavbarLink(whichLink);
} // function selectNavbarLink


