/*
	KNOWN ISSUE:
	strangely, when parsing through the XHTML, I'm running across a problem where the main UL,
	a LI within, then a nested UL contains LIs which for some reason return HasChildNodes = false
	even though these LIs contain a A tag around an IMG.  THE PAGE IS VALID XHTML.
	For now commented out the CheckForImages functions, using InitMenuDropdownRollovers instead.
	new work in progress is kept in dropdown_wip.js
*/
InitMenuDropdowns = function() {
	if (!document.getElementById) return
	//HideMenuDropdownSubs();
	InitMenuDropdownRollovers();
	InitMenuDropdownLists();
	//InitMenuDropdownReadjust();
}

//-------------------------------------------------------------------------------------------------------------

HideMenuDropdownSubs = function() {
	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.visibility = 'hidden';
						}
					}
				}
			}
		}
	}
}

//-------------------------------------------------------------------------------------------------------------

InitMenuDropdownRollovers = function() {
	// initialize dropdown rollover images
	var aPreLoadMenu = new Array();
	var sTempSrc;
	var aMenuImages = document.getElementsByTagName('img');
	for (var i = 0; i < aMenuImages.length; i++) {
		x = i;
		if (aMenuImages[i].className == 'RolloverMenuImg') {
			var src = aMenuImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);

			aMenuImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoadMenu[i] = new Image();
			aPreLoadMenu[i].src = hsrc;
			
			aMenuImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}
			aMenuImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}
//-------------------------------------------------------------------------------------------------------------

InitMenuDropdownLists = function() {
	// parse semantic lists; apply classes/rollover functions
	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") {
					node.onmouseover=function() {
						for (j=0; j<this.childNodes.length; j++) {
							if (this.childNodes[j].nodeName=="UL") {
								if (this.childNodes[j].getAttribute('id') != 'SelectedSubs') {
									this.childNodes[j].className = 'MenuListOver';
								}
							}
						}
					}
					node.onmouseout=function() {
						for (j=0; j<this.childNodes.length; j++) {
							if (this.childNodes[j].nodeName=="UL") {
								if (this.childNodes[j].getAttribute('id') != 'SelectedSubs') {
									this.childNodes[j].className = 'MenuListOff';
								}
							}
						}
					}
					for (j=0; j<node.childNodes.length; j++) {
						if (node.childNodes[j].nodeName=="UL") {
							//node.childNodes[j].style.visibility = 'visible';
							if (node.childNodes[j].getAttribute('id') != 'SelectedSubs') {
								node.childNodes[j].className = 'MenuListOff';
								node.childNodes[j].style.top = node.offsetTop + BodyTable.offsetTop + 'px';
								node.childNodes[j].style.left = BodyTable.offsetLeft + 166 + 'px';
							}
						}
					}
				}
			}
		}
	}	
}

//-------------------------------------------------------------------------------------------------------------

InitMenuDropdownReadjust = function() {
	// parse semantic lists; apply classes/rollover functions
	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 + 166 + 'px';
						}
					}
				}
			}
		}
	}	
}
//-------------------------------------------------------------------------------------------------------------

