
var totalAnchorWidth = 0;
var allAnchors;
var leftSpace = 0;
var elemWidth;

function prepNav() {
	var navWidth = 955;
	navUL = document.getElementById("nav");
	allAnchors = navUL.getElementsByTagName("a");
	
	for (x = 0; x < allAnchors.length; x++) {
		totalAnchorWidth += allAnchors[x].offsetWidth;
		}
		leftSpace = Math.round((navWidth - totalAnchorWidth)/2);
	
	for (x = 0; x < allAnchors.length; x++) {
		allAnchors[x].setAttribute("rel",x);
		allAnchors[x].onmouseover = overEffect;
		allAnchors[x].onmouseout = function() {
										navUL.style.background = "none";
									};
		}
	}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
		} else {
		window.onload = function() {
			oldonload();
			func();
			}
		}
	}
addLoadEvent(prepNav);

function overEffect(){
	elemWidth = this.offsetWidth;
	var currentPos = this.getAttribute("rel");
	var tempTotalAnchorWidth = 0;
	var vertPos;
	for (i = 0; i < currentPos; i++) {
		tempTotalAnchorWidth += allAnchors[i].offsetWidth;
		}
	totalLeftSpace = leftSpace + tempTotalAnchorWidth;
	
	navUL.style.background = "transparent url(assets/images/navHover.gif) no-repeat";
	if (elemWidth < 56) {
		//currBgWidth = 95;
		vertPos = "bottom";
		}
	else if (elemWidth > 55 && elemWidth < 90) {
		//currBgWidth = 107;
		vertPos = "center";
		}
	else {
		//currBgWidth = 143;
		vertPos = "top";
		}
		currBgWidth = 143;
		centerBg = totalLeftSpace - ((currBgWidth - elemWidth)/2)
	navUL.style.backgroundPosition = Math.round(centerBg) + "px " + vertPos;
	};