// Global Navigation Variables

var	currTopNav = "";
var	currLeftNav = "";
var activeMenu;
var menuColor = "";
var firstPass = "y";
	
function menuOpen () {
	
// Get the ID names for the leftNav from the <body> tag
	var bodyTag = ns6? document.getElementsByTagName('body')[0]: document.all.tags("body")[0];
	
// Check to see if page uses new CSS method for setting leftNav and TopNav from the BODY tag.
// If so, get the values. If not values were already specified in the javaScript within the page.

	if (bodyTag.className != "") {
		currTopNav = bodyTag.id.substring(0, bodyTag.id.lastIndexOf("on"));
		currLeftNav = bodyTag.className;
		menuColor = document.getElementById('lefttitlebox').style.backgroundColor;	// Get color of left nav titlebox to use for menu button highlight color
	}
	
// Turn Top Navigation menu On

	if (document.getElementById(currTopNav)){						// Check for valid id reference
		element = document.getElementById(currTopNav);
		element=ns6? element.parentNode : element.parentElement;	// backup to <li> tag
		element.className="topNav_item_On";							// change style to Highlighted
	}
		
// Turn Left Navigation menu On

	if (!document.getElementById(currLeftNav)){						// Check for valid id reference
		return 0;
	}
	
	sourceElement = document.getElementById(currLeftNav);
	element = sourceElement;

//	alert ("Before While: tag = " + element.tagName + "    Id = " + element.id);

// Opens the expanding left navigation to the current page 

	if (bodyTag.className != "") {
		expandNav_CSS();
	}
	else {
		expandNav_nonCSS();
	}
}


function expandNav_CSS() {
	while (ns6&&element.parentNode||(ie&&element.parentElement)){
		element=ns6? element.parentNode : element.parentElement;     //up a level

//		alert ("While Loop:  tag = " + element.tagName + "    Id = " + element.id + "    Class = " + element.className);
		
		if (element.className=="list_1_item"){
			element.className="list_1_item_On";				// change style to Highlighted
			element.style.backgroundColor = menuColor;		// modify base style color to color of "lefttitlebox" style which may have been overridden by and in-line style. 

			b = ns6? element.getElementsByTagName('ul')[0]: element.all.tags("ul")[0];				// folder contain contents ?
			if (firstPass == "y" && (b != null)){			// expand tier two menu
				b.style.display="";
			}
			firstPass = "n";
			break;											// At the top. ALL DONE
		}
		if (element.className=="list_2_item"){
			element.className="list_2_item_On";				// change style to Highlighted
			
			b = ns6? element.getElementsByTagName('ul')[0] : element.all.tags("ul")[0];				// folder contain contents ?
			if (firstPass == "y" && (b != null)){			// expand tier three menu
				b.style.display="";
			}			
			firstPass = "n";
		}
		if (element.className=="navList_2x" || element.className=="navList_3"){
			sourceElement.className="menuText_On";			// change style to Highlighted
			element.style.display="";
			firstPass = "n";
		}		
		if (element.className=="list_3_item"){
			element.className="list_3_item_On";				// change style to Highlighted
			firstPass = "n";
		}
	}									// end while loop
	element.style.display="";           // expand sub-menu list
}

function expandNav_nonCSS() {
	
// Legacy routine for expanding nonCSS left Navigation menus. Once the entire site is converted to pure CSS, these can be deleted.
	
	while (ns6&&element.parentNode||(ie&&element.parentElement)){
		element=ns6? element.parentNode : element.parentElement;     //up a level
		
//		alert ("While Loop:  tag = " + element.tagName + "    Class = " + element.className);

		if (element.className=="list_1_item"){
			x = getImgObj(element);							// get name of Menu Image
			document[x.name].src=eval(x.name + "_set.src");	// swap Menu Image to SET state
			activeMenu = x.name;							// record active menu item 
			b = ns6? element.getElementsByTagName('ul')[0]: element.all.tags("ul")[0];				// folder contain contents ?
//			alert ("b = " + b.tagName);
			if (firstPass == "y" && (b != null)){			// expand tier two menu
				b.style.display="";
			}
			firstPass = "n";
			break;											// At the top. ALL DONE
		}
		if (element.className=="list_2_item"){
			element.style.listStyleImage="url(/images/gui/bullet_open.gif)";  // Change bullet for open menu item
			b = ns6? element.getElementsByTagName('ul')[0] : element.all.tags("ul")[0];					// folder contain contents ?
			if (firstPass == "y" && (b != null)){			// expand tier three menu
				b.style.display="";
			}			
			firstPass = "n";
		}
		if (element.className=="navList_2x" || element.className=="navList_3"){
			sourceElement.className="menuText_On";			// Switch menu text class to highlighted
			element.style.display="";
			firstPass = "n";
		}		
		if (element.className=="list_3_item"){
			sourceElement.className="menuText_On";			// Switch menu text class to highlighted		
			firstPass = "n";
		}
	}									// end while loop
	element.style.display="";           // expand sub-menu list
}


// Legacy Routines that are only need to keep non-converted pages functioning properly.
// Once the entire site is converted to pure CSS, these can be deleted.

function swapImg() {

  if(!document.images) return;
  var args = swapImg.arguments;
  for(var i=0;i < args.length;i+=2) {
    var imgSrc = (args[i + 1].indexOf('[') != -1) ? eval(args[i + 1] + '.src') : args[i + 1];
    if(document.getElementById(args[i])){
		document.getElementById(args[i]).src = imgSrc;
	}
  }
}

function setTopNav(imgName)							// Sets the graphic to Blue for the active top navigation
{		
  if(!document.images || imgName == "") return;
	document[imgName].src=eval(imgName + "_set.src");
}


function rollOn(imgObj)
{
	imgName = imgObj.name;
	if(!document.images) return;
  
	if (imgName != activeMenu)
	{
	document[imgName].src=eval(imgName + "_on.src");
	}
}

function rollOff(imgObj)
{	
	imgName = imgObj.name;
	if(!document.images) return;
	if (imgName != activeMenu)
	{
	document[imgName].src=eval(imgName + "_off.src");
	}
}

function getImgObj(element)
// This function returns the image object that is nested within another HTML element such as an anchor tag <a href=""><img src="/images/foo.gif" id="foo" name="foo"></a>
{	
	return(ns6? element.getElementsByTagName('img')[0] : element.all.tags("img")[0]);	// get name of Image
}