// browser is IE
var broserIsIE = /*@cc_on!@*/false;

startList = function() {	
	if (document.getElementById) {
		navRoot = document.getElementById("nav");
		if (!navRoot) return;
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					alignMenu(this);
					
					// Hack to hide any select box under menu in IE6.
					if (broserIsIE && (uls = this.getElementsByTagName('ul')[0])) {
						var myIFrame = document.getElementById('selectsBelowMenuIEHack');				
						var med = getPos(uls);
						var myIFrame = document.getElementById('selectsBelowMenuIEHack');
						myIFrame.style.width = med.w;
						myIFrame.style.height = med.h;
						myIFrame.style.top= med.y;
						myIFrame.style.left= med.x;
						myIFrame.style.display = 'block';
					}
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
					
					// Hack to hide any select box under menu in IE6.
					if (broserIsIE) {
						var myIFrame = document.getElementById('selectsBelowMenuIEHack');
						myIFrame.style.display = 'none';
					}
				}
			}
		}
	}
}

function alignMenu(elm) {
	function getPos(el) {
		var r = {x: el.offsetLeft, y: el.offsetTop, w: el.offsetWidth, h: el.offsetHeight};
		
		if (el.offsetParent) {
		   var tmp = getPos(el.offsetParent);
		   r.x += tmp.x;
		   r.y += tmp.y;
		}
		return r;
	}

	elm.className+=" over";
	
	// check size of container element & aline menu with it
	var uls;
	if (uls = elm.getElementsByTagName('ul')[0]) {
		var main;
		try {
			main = getPos(document.getElementById('page'));
			main = (main.x + main.w);
		} catch (e) {
			main = document.body.offsetWidth;
		}
		var doc = document.body.offsetWidth;
			
		var med = getPos(uls);
		
		med = med.x + med.w;
		
		// align position
		if (main < med) {
			uls.style.left = (main - med - 7) + 'px';
		}
	}

	// replace old event
	elm.onmouseover = function() {
		this.className+=" over";
		
		// Hack to hide any select box under menu in IE6.
		if (broserIsIE && (uls = this.getElementsByTagName('ul')[0])) {
			var myIFrame = document.getElementById('selectsBelowMenuIEHack');				
			var med = getPos(uls);
			var myIFrame = document.getElementById('selectsBelowMenuIEHack');
			myIFrame.style.width = med.w;
			myIFrame.style.height = med.h;
			myIFrame.style.top= med.y;
			myIFrame.style.left= med.x;
			myIFrame.style.display = 'block';
		}
	}
}
window.onload=startList;
