$('a.external').live('click',function(e) { e.preventDefault(); });


function MenuHover(elem) {
	var scope = this;
	this.interval = false;
	this.elem = elem;
	this.bgy = (elem.css('background-position-y')) ? elem.css('background-position-y') : elem.css('backgroundPosition').split(" ")[1];
		
	if(!this.elem.hasClass('selected')) {
		this.elem.hover(function() { scope.ShowHover(); }, function() { scope.HideHover() } );
	}
}

MenuHover.prototype.ShowHover = function() {
	var scope = this;
	clearInterval(this.interval);
	this.interval = setInterval(function() { scope.MoveBackground(6,-85); },25);
}

MenuHover.prototype.HideHover = function() {
	var scope = this;
	clearInterval(this.interval);
	this.interval = setInterval(function() { scope.MoveBackground(-6,-160); },25);
}

MenuHover.prototype.MoveBackground = function(x,max) {
	var curX_ = (this.elem.css('background-position-x')) ? parseInt(this.elem.css('background-position-x')) : parseInt(this.elem.css('backgroundPosition').split(" ")[0]);
	if(max == -85) {
		if(curX_ > max) { clearInterval(this.interval); }
		else { 
			if(this.elem.css('background-position-x')) {
				this.elem.css('background-position-x',curX_+x+'px');
			} else {
				this.elem.css('backgroundPosition',curX_+x+'px '+this.bgy); 
			}
		}
	} else {
		if(curX_ < max) { clearInterval(this.interval); }
		else {
			if(this.elem.css('background-position-x')) {
				this.elem.css('background-position-x',curX_+x+'px');
			} else {
				this.elem.css('backgroundPosition',curX_+x+'px '+this.bgy); 
			}
		}
	}
}

$('#header li a').each(function() { window[$(this).text()] = new MenuHover($(this));});

