/*
Shipserv statometer script
Ben Hayes
www.jackfruitdesign.com
April 2008
*/

/* This function written by Simon Willison: http://simon.incutio.com/archive/2004/05/26/addLoadEvent */

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
		}
	}
}

addLoadEvent(setupStatometer);

function setupStatometer() {
	//Only run this if we have a statometer:
	if(!document.getElementById('stat')) return false;

	var statometer, stat1, stat2, stat3, stat4, stat5, stat6;
	statometer = document.getElementById('stat');
	stat1 = document.getElementById('statnav1');
	stat2 = document.getElementById('statnav2');
	stat3 = document.getElementById('statnav3');
	stat4 = document.getElementById('statnav4');
	stat5 = document.getElementById('statnav5');
	stat6 = document.getElementById('statnav6');

	stat1.onmouseover = function() { activateStat(statometer,this,0); }
	stat2.onmouseover = function() { activateStat(statometer,this,200); }
	stat3.onmouseover = function() { activateStat(statometer,this,400); }
	stat4.onmouseover = function() { activateStat(statometer,this,600); }
	stat5.onmouseover = function() { activateStat(statometer,this,800); }
	stat6.onmouseover = function() { activateStat(statometer,this,1000); }
}

function activateStat(statometer,thisStat,xOffset) {
	thisStat.style.backgroundPosition = "left bottom";
	statometer.style.backgroundPosition = "-" + xOffset + "px 0px";
	deactivateStats(statometer,thisStat);
}

function deactivateStats(statometer,exception) {
	var stats = statometer.getElementsByTagName('li');
	for(var i=0; i<stats.length; i++) {
		if(stats[i] != exception) {
			stats[i].style.backgroundPosition = "left top";
		}
	}
}
