var timer
var timeOut = 8000;

$(document).ready(function(){
	
	rotatorInit($('#bann'));
	timer = setTimeout(nextRotate, timeOut);
	
	$('#bann').mouseenter(function(){
		clearTimeout(timer);
	});
	
	$('#bann').mouseleave(function(){
		timer = setTimeout(nextRotate, timeOut);
	});
	
});

function rotatorInit(wrap) {

	wrap.find('.buttons a').click(function(){
		
		var col = $(this).prevAll().length;
		
		wrap.find('.belt').animate({
			left: 964 * col * -1
		});
		
		wrap.find('.buttons a').removeClass('active');
		$(this).addClass('active');
		
		
	});
	
	
}

function nextRotate() {
	
	var col = parseInt($('#bann').find('.belt').css('left')) / -964;
	
	if (col==3) {
		var nextCol = 0;
	} else {
		var nextCol = col + 1;
	}

	$('#bann').find('.buttons a').removeClass('active');
	$('#bann').find('.buttons a:eq(' + nextCol + ')').addClass('active');

	$('#bann').find('.belt').animate({
		left: 964 * nextCol * -1
	});

	timer = setTimeout(nextRotate, timeOut);
}

