/*	DOM-compliant Left Nav Dropdown Menu Javascript
	
	-	Works in conjunction with /ai/assets/css/dropdowns.css
	-	Also works based on settings in /ai/include/nav/i_functions_nav.asp and i_mainmenu.asp
*/
InitMenuDropdowns = function() {
	if (!document.getElementById) return
	InitMenuDropdownRollovers();
	InitMenuDropdownLists();
	//InitMenuDropdownReadjust();
}

//-------------------------------------------------------------------------------------------------------------

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") {
							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';
							} else {
								node.childNodes[j].style.display = 'block';
							}
						}
					}
				}
			}
		}
	}	
}

//-------------------------------------------------------------------------------------------------------------

InitMenuDropdownReadjust = function() {
	//	parse semantic lists; apply classes/rollover functions
	//	currently set to fire on window.resize (set in 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 + 166 + 'px';
						}
					}
				}
			}
		}
	}	
}
//-------------------------------------------------------------------------------------------------------------

