var numPanels = 1;
var currentPanel = 0;
var toHide = 0;

$(document).ready(function(){
	var timer = setInterval('rotatePanels()', 7000);
	$('#dots a').click(function(){
		clearInterval(timer);
		rotatePanels($(this).attr('id'));
		return false;
	})
});

function rotatePanels(rotateTo){
	if (!rotateTo) {
		toHide = currentPanel;
		currentPanel++;
		if (currentPanel > numPanels) {
			currentPanel = 0;
			toHide = 1;
		}
	} else {
		toHide = currentPanel;
		currentPanel = rotateTo;
	}


	//console.log('hiding ' + toHide + ' / ' + currentPanel);

	$('#front .text div:eq(' + toHide + ')').stop().animate({
		left: '+=450'
	}, 1000, function(){
		$('#front .text div:eq(' + currentPanel + ')').hide().css({'left': '0'}).fadeIn('2000');
		$('#front img:eq(' + toHide + ')').fadeOut('2000', function(){
				$('#front img:eq(' + currentPanel + ')').fadeIn('2000');
		});
		$('#dots a').removeClass('active');
		$('#' + currentPanel).addClass('active');
	});


}
