var timer;
var currentImage = 0;
var testimonials = new Array();

function startTimer(){
	timer = setTimeout("nextImage()", 12000);
}

function stopTimer(){
	clearTimeout(timer);
	timer = null;
}

function nextImage(){
	switch(currentImage){
		case 0:
			$(".testiImage:eq(0)").fadeOut("def");
			$(".testiImage:eq(1)").fadeIn("def");
			break;
		case 1:
			$(".testiImage:eq(1)").fadeOut("def");
			$(".testiImage:eq(2)").fadeIn("def");
			break;
		case 2:
			$(".testiImage:eq(2)").fadeOut("def");
			$(".testiImage:eq(0)").fadeIn("def");
			break;
	}
	currentImage = (currentImage < 2)? currentImage+1:0;
	startTimer();
}

function clickTab(clickedTab){
	$(".testiImage:eq(" + currentImage + ")").fadeOut("def");
	$(".testiImage:eq(" + clickedTab + ")").fadeIn("def");
	currentImage = clickedTab;
}

$(document).ready(function() {
	testimonials[0] = $(".tab:eq(1)").attr("name");
	testimonials[1] = $(".tab:eq(3)").attr("name");
	testimonials[2] = $(".tab:eq(5)").attr("name");
	
	startTimer();
	
	$("img.tab").click(function(){
		stopTimer();
				
		clickedImage = jQuery.inArray($(this).attr("name"), testimonials);
		clickTab(clickedImage);
		
		startTimer();
	});
});