/**** NAV MENU DROPDOWNS ***/
addLoadEvent(function() {
	var navLIs = document.getElementById("navWrap").getElementsByTagName("LI");
	for (var i=0; i<navLIs.length; i++) {
		navLIs[i].onmouseover = function() {
			var x = getScreenWidth();
			var liX = this.offsetWidth;
			var levelArray = getLevelsDeep(this);
			var level = levelArray[0];
			var levelObj = levelArray[1];
			var OffsetLeft = getObjectOffsetDimension(levelObj);
			
			var total = (OffsetLeft+(level*180));

			if (total > x) {
				this.className += " left";
			}
			if (this.className.match("parent") != null) {
				this.className += " both";
			} 
			this.className += " active";
		}
		navLIs[i].onmouseout = function(e) {
			this.className = this.className.replace(/active/g,"");
			this.className = this.className.replace(/both/g,"");
			this.className = this.className.replace(/left/g,"");
		}
	}
})

/**** NAV FUNCTION ***/
function getScreenWidth() {
	if (document.documentElement.clientWidth > document.body.scrollWidth) {
		return document.documentElement.clientWidth;
	} else if (document.body.clientWidth > document.body.scrollWidth) {
		return document.body.clientWidth;
	} else {
		return document.body.scrollWidth;
	}
}
/**** NAV FUNCTION ***/
function getObjectOffsetDimension(obj) {
	var value = 0;
	value = obj.offsetLeft;
	while ((obj = obj.offsetParent) != null) { 
		value += obj.offsetLeft; 
	}
	return value;
}
/**** NAV FUNCTION ***/
function getLevelsDeep(obj) {
	var value = 0;
	var prevObj = obj;
	while (obj != null) { 
		if (obj.nodeName == "UL") {
			value++;
			if (obj.parentNode.id == "navWrap") {
				break;				
			}
		}
		prevObj = obj;
		obj = obj.parentNode;
	}
	return new Array(value,prevObj);
}

/* nav.js Used throughtout the site for top navigation  */
function addEvent(elem, type, handle) {
        if ( elem.addEventListener ) {
                elem.addEventListener( type, handle, false );
        } else if ( elem.attachEvent ) {
                elem.attachEvent( "on" + type, handle );
        }
}
function addLoadEvent(handle) {
        addEvent(window, 'load', handle);
}

addLoadEvent(function() {
        var navLIs = document.getElementById("navWrap").getElementsByTagName("li");
        for (var i=0; i<navLIs.length; i++) {
                navLIs[i].onmouseover = function() {
                        if (this.className.match("parent") != null) {
                                this.className += " both";
                        }
                        this.className += " active";
                }
                navLIs[i].onmouseout = function() {
                        this.className = this.className.replace(/active/g,"");
                        this.className = this.className.replace(/both/g,"");
                }
        }
});


