$(document).ready(function() {
	tabSlide();
	testimonySlide();
	$('.tabContainer .tabs').bind('click', function() {
		var tabIndex = $('.tabContainer .tabs').index(this);
		var $tabItemArr = $('.tabContentBox .tabItem');
		
		$('.tabContainer .tabs').removeClass("selected");
		$(this).addClass("selected");
		$('.tabContentBox .tabItem').hide();
		$tabItemArr[tabIndex].style.display = "block";
		
		clearInterval(alertTimerId);
	});
	$('.customerSay .quoteCount span').bind('click', function() {
		var testimonyIndex = $('.customerSay .quoteCount span').index(this);
		
		$('.customerSay .quoteCount span').removeClass("active");
		$(this).addClass("active");
		$('.customerSay .quote').hide();
		$('.customerSay .quote:eq('+testimonyIndex+')').show();
		
		clearInterval(alertTimerId1);
	});
});

var count = 0,count1 = 0, alertTimerId, alertTimerId1;
function testimonySlide(){
	$('.customerSay .quote:gt(0)').hide();
	alertTimerId1 = setInterval ( "cycleTestimony()", 5000 );
}
function tabSlide(){
	$('.tabItem:gt(0)').hide();
	alertTimerId = setInterval ( "cycleTabs()", 15000 );
}
function cycleTestimony(){
	var temp = count1 - 1;
	if(temp == -1)	temp = 4;
		
	$('.quoteCount span:eq('+temp+')').removeClass('active');
	$('.quoteCount span:eq('+count1+')').addClass('active');
	$('.customerSay .quote:eq('+temp+')').hide();
	$('.customerSay .quote:eq('+count1+')').show();
	count1++;
	if(count1 == $('.tabContainer .tabs').length)
		count1 = 0;
}
function cycleTabs(){
	var $tabArr = $('.tabContainer .tabs');
	var $tabItemArr = $('.tabContentBox .tabItem');
		
	var temp = count - 1;
	if(temp == -1)	temp = 4;
		
	$tabArr[temp].setAttribute("class"," tabs ");
	$tabArr[temp].setAttribute("className"," tabs ");
	$tabArr[count].setAttribute("class"," tabs selected ");
	$tabArr[count].setAttribute("className"," tabs selected ");
	$tabItemArr[temp].style.display = "none";
	$tabItemArr[count].style.display = "block";
	count++;
	if(count == $('.tabContainer .tabs').length)
		count = 0;
	
}