// Initialize variables
// Navigation flags to control when to Hide/Show HTML SELECT dropdowns in IE6's browser bug.
var selectBoxFlag = 0;

// This function hides select boxes in IE that fall underneith a layer.
hideSelectBoxes = function(action) {
	if ((action == 'visible') && (selectBoxFlag)) return;
	else if ((browser.isIE6x) && ($('content') && (selectRoot = $('content').getElementsByTagName('select')))) {
		for (i=0; i<selectRoot.length; i++ ) {
			if (selectRoot[i].className.match(/elementToHideOnMenuOpen/)) {
				selectRoot[i].style.visibility = action;
			}
		}
	}
}

// Controls the utility bar's primary open/close functionality
utilityNav = function () {
	if (cssdropdownRoot = $('my_links')) {
		cssdropdownRoot = $('my_links').getElementsByTagName('li');
		liNodes = $A(cssdropdownRoot);
		for (x=0; x<liNodes.length; x++) {
			if (liNodes[x].className == '') {
				divNodes = liNodes[x].getElementsByTagName('div');
					for (y=0; y<divNodes.length; y++) {
						if (divNodes[y].className == "close") {
							aNode = divNodes[y].getElementsByTagName('a');
							aNode[0].onclick = function() {
								this.href="javascript:void(0)";
								utility(this);
							}
						}
					}
				aNode = liNodes[x].getElementsByTagName('a');
				//alert(divNode[divNode.length-1].className);
				aNode[0].onclick = function() {
				this.href="javascript:void(0)";
				utility(this);
				}
			}
		}
	}
}

// Top navigation menu control
topNav = function() {
	if ((document.all)&&(document.getElementById)&&(cssdropdownRoot = $('nav_list'))) {
		cssdropdownRoot = $('nav_list').getElementsByTagName('li');
		nodes = $A(cssdropdownRoot);
		for (x=0; x<nodes.length; x++) { // length = 7
			node = nodes[x];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					// mimics the :hover functionality
					this.className+=" over";
					selectBoxFlag++;
					hideSelectBoxes('hidden');
				}
				node.onmouseout=function() {
					// mimics the :hover functionality
					this.className=this.className.replace(" over", "");
					selectBoxFlag--;
					if (!selectBoxFlag) hideSelectBoxes('visible');
				}
			}
		}
	}
}

// provides rollover functionality.  Uses classnames to determin file name.
rollover = function() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('roll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/roll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/roll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}

// These functions are activated upon page load. They embed JavaScript without function calls from appearing within the HTML.
init = function() {
	utilityNav(); // activate utility navigational links
	topNav(); // activate top navigation
	rollover(); // general function for embedded image rollovers
}


// Standard Global Fully Browser-compat onload function init call.
if (window.addEventListener)
window.addEventListener("load", init, false)
else if (window.attachEvent)
window.attachEvent("onload", init)
else if (document.getElementById)
window.onload=init;