addEvent(window,'load',initMenuAnimation);
var N_INT_ID = -1;
var O_CURR_ITEM;
function initMenuAnimation() {
	var oMenu = getObjById('menu');
	if (!oMenu.getElementsByTagName) {
		return;
	}
	var aItms = oMenu.getElementsByTagName('a');
	var nPosH,nPosV;
	for (var i = 0; i < aItms.length; i++) {
		nPosH = aItms[i].offsetWidth / 2 - 7;
		nPosV = aItms[i].offsetHeight;
		aItms[i].style.backgroundPosition = nPosH + 'px ' + nPosV + 'px';
		// Safari can't recall the value so don't bother continuing
		if (aItms[i].style.backgroundPosition != nPosH + 'px ' + nPosV + 'px') {
			aItms[i].style.backgroundPosition = nPosH + 'px ' + (nPosV - 7) + 'px';
			return;
		}
		aItms[i].style.backgroundImage = 'url(css/images/up.gif)';
		aItms[i].style.backgroundRepeat = 'no-repeat';
		aItms[i].onmouseover = changeBg;
		aItms[i].onmouseout = changeBg;
		
	}
}
function animateBgs() {
	var oMenu = getObjById('menu');
	var aItms = oMenu.getElementsByTagName('a');
	var nPosH,nPosV;
	var bAnimating = false;
	for (var i = 0; i < aItms.length; i++) {
		var nDir = O_CURR_ITEM == aItms[i] ? -1 : 1;
		var nCurrPos = parseInt(suffix(aItms[i].style.backgroundPosition,' '));
		if (nCurrPos + nDir > aItms[i].offsetHeight - 7 && nCurrPos + nDir < aItms[i].offsetHeight) {
			bAnimating = true;
			nPosH = aItms[i].offsetWidth / 2 - 7;
			nPosV = nCurrPos + nDir;
			aItms[i].style.backgroundPosition = nPosH + 'px ' + nPosV + 'px';
		}
	}
	if (!bAnimating) {
		window.clearInterval(N_INT_ID);
		N_INT_ID = -1;
	}
}
function changeBg(e) {
	if (!e) {
		var e = window.event;
	}
	if (e.type == 'mouseover') {
		O_CURR_ITEM = (e.target) ? e.target : e.srcElement;
	} else if (e.type == 'mouseout') {
		O_CURR_ITEM = '';
	}
	if (N_INT_ID == -1) {
		N_INT_ID = window.setInterval('animateBgs()',30);
	}
}

function getObjById(id) {
	if (document.all) {
		return document.all(id);
	}
	return document.getElementById(id);
}
function suffix(str,chr) {
	var indx = str.lastIndexOf(chr) + 1;
	str = str.substr(indx);
	return str;
}
function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be added");
  }
}
