var rotate = true;
var rotators = new Array();
var at = 0;

$(document).ready(function(){
	//$('#Backgrounds div').css({display: 'none'});
	$('#Buttons li a').each(function(){
		var id = $(this).attr('id');
		var n = rotators.length; 
		$(this).click(function(e) {
			rotate = false;
			if ($(this).hasClass('active')) return false;
			var pid = $('#Buttons li .active').attr('id');
			swapto(n);
			return false;
		});
		rotators.push(id);
	});
	window.setTimeout('swap()', 5000);
	$('#arrowleft').click(function(e) {
		rotate = false;
		var next = at - 1;
		if (next < 0) next = rotators.length -1;
		swapto(next);
	});
	$('#arrowright').click(function(e) {
		rotate = false;
		var next = (at + 1) % rotators.length;
		swapto(next);
	});
});
function swap() {
	if (!rotate ) return false;
	var next = (at+1) % rotators.length;
	swapto(next);
	window.setTimeout('swap()', 5000);
}

function swapto(next) {
	var id = rotators[next];
	var pid = rotators[at];
	$('#'+pid).removeClass('active');
	$('#'+id).addClass('active');
	if ((next > at || (next == 0 && at == (rotators.length - 1))) && !(at == 0 && next == (rotators.length - 1))) {
		$('#Info .'+pid).animate({left: 988});
		$('#Info .'+id).css({left: -988, display: 'block'});
		$('#Info .'+id).animate({left: 0});
	} else {
		$('#Info .'+pid).animate({left: -988});
		$('#Info .'+id).css({left: 988, display: 'block'});
		$('#Info .'+id).animate({left: 0});
	}
	at = next;
}

