// Slider X-Treme (c) SNAPFX WEBDESIGN www.snapfx.com.au

var xpos = 0;//position of slider
var moduleWidth = 286;
var globalTimer;
var autoTimer;
var rate = .05;
var speed = 2;
var tabs = 7;
var tab = 0;
var lis;

function slide(y) {
	clearTimeout(globalTimer);
	clearTimeout(autoTimer);
	y = parseInt(y);
	tab = y;
if (typeof lis != "undefined" && lis != null && lis != false)
{

for(i = 0; i < lis.length;i++) {
lis[i].style.background="none";
}
lis[y].style.background="url(images/slider/bg_menu_over_right.png) top left repeat-x";
}

	var dpos = y*moduleWidth;
	var target = document.getElementById("moving_part");
	if(xpos != dpos) {
		animate(dpos,target,.1);
	}
}

function animate(dpos,what,slowstart) {
	if(xpos != dpos) {
		var diff = (xpos - dpos)*-1;
		var stepdist = diff*(rate*slowstart);
		
		if(slowstart < 1) {
			slowstart += .05;
		}
		
		if(stepdist < 1 && stepdist > 0) {
			stepdist = 1;
		}
		else if(stepdist > -1 && stepdist < 0) {
			stepdist = -1;
		}
		xpos += Math.round(stepdist);
		//alert(xpos + " | " + dpos + " | " + stepdist);
		what.style.left=-xpos + "px";
		globalTimer = setTimeout(function(){animate(dpos,what,slowstart)},speed);
	}
	else {
		setTimeout(function(){automate()},10000);
	}
}

function automate() {
	if(tab < tabs-1) {
		var newtab = tab+1;
	}
	else {
		var newtab = 0;
	}
	autoTimer = setTimeout(function(){slide(newtab)},5000);
}

function setList() {
	lis = document.getElementById('slider_cont').getElementsByTagName('li');
}

window.onload = function() {
	setList();
	automate();
}


