/*---------------------------------------------------------------------
	NSS Dynamic Dropdown Menu JS

	REQUIREMENTS:
		Works in conjunction with /assets/css/dropdowns.css
		Utilizes functions found in /assets/js/functions.js
	
	USAGE:
		Make sure function InitMenuDropdowns() is called in the window.onload event (found in /assets/js/init.js).
		
-----------------------------------------------------------------------*/

/*-------------------------------
	general setup
---------------------------------*/
var iMenuWidth = 150;
var iMenuWidth = 147;	//	Altered this value so we can get a visual overlap so borders don't double up
var iMenuTop = 0; 

/*-------------------------------
	InitMenuDropdowns() - called from init.js
---------------------------------*/
InitMenuDropdowns = function() {
	if (!document.getElementById) return
	InitMenuDropdownLists();
	//InitMenuDropdownReadjust();
}

/*-------------------------------
	InitMenuDropdownLists()
---------------------------------*/
InitMenuDropdownLists = function() {
	// parse semantic lists; apply classes/rollover functions
	var mainNavRoot = document.getElementById("Nav");
	for (h=0; h<mainNavRoot.childNodes.length; h++) {
		node = mainNavRoot.childNodes[h];
		if (node.nodeName=="UL") {
			mainNavUL = mainNavRoot.childNodes[h];
			for (i=0; i<mainNavUL.childNodes.length; i++) {
				node = mainNavUL.childNodes[i];
				if (node.nodeName=="LI") {
					InitMenuDropdownListsDive(node);
				}
			}
		}
	}	
}

/*-------------------------------
	InitMenuDropdownListsDive()
---------------------------------*/
InitMenuDropdownListsDive = function(currentNode) {
	// parse semantic lists; apply classes/rollover functions

	if (currentNode.nodeName == "LI") {
		currentNode.onmouseover=function() {
			for (j=0; j<this.childNodes.length; j++) {
				if (this.childNodes[j].nodeName=="UL") {
						//alert(this.childNodes[j].nodeName);
					if (this.childNodes[j].className != 'SelectedSubs') {
						this.childNodes[j].className = 'MenuListOver';
					}
				}
			}
		}
		currentNode.onmouseout=function() {
			for (j=0; j<this.childNodes.length; j++) {
				if (this.childNodes[j].nodeName=="UL") {
					if (this.childNodes[j].className != 'SelectedSubs') {
						this.childNodes[j].className = 'MenuListOff';
					}
				}
			}
		}
		for (j=0; j<currentNode.childNodes.length; j++) {
			if (currentNode.childNodes[j].nodeName=="UL") {
				if (currentNode.childNodes[j].className != 'SelectedSubs') {
					currentNode.childNodes[j].className = 'MenuListOff';
					// this positioning has problems with Opera - look into this once other problems are fixed
					SetAbsPos(currentNode.childNodes[j], iMenuWidth, iMenuTop + currentNode.offsetTop);
				}
			}
		}
	}

	//	Gotta deal with XML whitespace in DOM: Recursion
	if (getFirstChild(currentNode)) {
		InitMenuDropdownListsDive(getFirstChild(currentNode));
	}
	if (getNextSibling(currentNode)) {
		InitMenuDropdownListsDive(getNextSibling(currentNode));
	}
	
}
/*-------------------------------
	InitMenuDropdownReadjust() - Can be called from window.onresize in init.js
---------------------------------*/
/*
InitMenuDropdownReadjust = function() {
	//	parse semantic lists; apply classes/rollover functions
	//	currently set to fire on window.resize (set in /assets/js/init.js)
	var BodyTable = document.getElementById("BodyTable");
	var mainNavRoot = document.getElementById("MainMenu");
	for (h=0; h<mainNavRoot.childNodes.length; h++) {
		node = mainNavRoot.childNodes[h];
		if (node.nodeName=="UL") {
			mainNavUL = mainNavRoot.childNodes[h];
			for (i=0; i<mainNavUL.childNodes.length; i++) {
				node = mainNavUL.childNodes[i];
				if (node.nodeName=="LI") {
					for (j=0; j<node.childNodes.length; j++) {
						if (node.childNodes[j].nodeName=="UL") {
							node.childNodes[j].style.top = node.offsetTop + BodyTable.offsetTop + 'px';
							node.childNodes[j].style.left = BodyTable.offsetLeft + iMenuWidth + 'px';
						}
					}
				}
			}
		}
	}	
}
/*

/*---------------------------------------------------------------------
	end NSS Dynamic Dropdown Menu JS
-----------------------------------------------------------------------*/
