var timerid;
var opt;
var destx = 0;
var n = 0;
var rw_act;
function do_rw(n)
{

	//if(n == rw_act) return;
	if(rw_act != null) {
		
		document.getElementById('rw_img_' + (rw_act + 1)).src = 'img/rw_' + (rw_act + 1) + '.gif';
	}
	rw_act = n;
	document.getElementById('rw_img_' + (rw_act + 1)).src = 'img/rw_' + (rw_act + 1) + '_on.gif';
	
	destx = -n * 781;
	if(timerid) window.clearInterval(timerid);
	timerid = window.setInterval("tween()", 1);
}

function tween()
{
	// get current x of desired tab and calc delta
	var c = document.getElementById('th_content');
	var x = parseInt(c.style.marginLeft);
	var dx = Math.ceil(Math.sqrt(Math.abs(destx - x)) * 3) + 1;
	if(destx < x) dx *= -1;
	
	if(Math.floor(Math.abs(x - destx)) <= 5 || n == 100) {
		c.style.marginLeft = destx + 'px';
		window.clearInterval(timerid);
		n = 0;
		timerid = 0;
	} else {
		c.style.marginLeft = (x + dx) + 'px';
		n++;
	}	
}

function init()
{
	//do_rw(Math.round(Math.random() * 3));
	do_rw(0);
}

window.onload=init