var i = 1;

function openTab(tab){
	
	var TABWIDTH = '35px';

	if (tab == 1) {
	
		$('#section2').animate({
			left: '622px',
			width: TABWIDTH
		}, 500);
		
		$('#section3').animate({
			left: '650px',
			width: TABWIDTH
		}, 500);
		
		$('#section4').animate({
			left: '675px',
			width: TABWIDTH
		}, 500);
		
	}
	
	else if (tab == 2) {
	
		$('#section2').animate({
			left: '22px',
			width: '640px'
		}, 500);
		
		$('#section3').animate({
			left: '650px',
			width: TABWIDTH
		}, 500);
		$('#section4').animate({
			left: '675px',
			width: TABWIDTH
		}, 500);
		
	}
	
	else if (tab == 3) {
	
		$('#section2').animate({
			left: '22px',
			width: TABWIDTH
		}, 500);
		
		$('#section3').animate({
			left: '49px',
			width: '656px'
		}, 500);
		$('#section4').animate({
			left: '675px',
			width: TABWIDTH
		}, 500);
		
	}
	
	
	else if (tab == 4 || tab === 0) {
	
		$('#section2').animate({
			left: '22px',
			width: TABWIDTH
		}, 500);
		
		$('#section3').animate({
			left: '49px',
			width: TABWIDTH
		}, 500);
		
		$('#section4').animate({
			left: '75px',
			width: '632px'
		}, 500);
		
	}
	
	else {
		var index = '';
		i++;
		
		if (i % 4 == 0) {
			index = 3;
		}
		else {
			index = (i % 4) - 1;
		}
		
		openTab(i%4);
		$('.tab').removeClass('current');
		$('.tab:eq(' + index + ')').addClass('current');
	}
	
}

$(document).ready(function(){
	
	// Auto-scroll accordion every 5 sec
	
	var auto = setInterval('openTab()', 5000);	
			
	// 4 Tab Homepage Accordian
	
	$('.tab').click(function(){
		clearInterval(auto);
		openTab($('.tab').index(this)+1);
		$('.tab').removeClass('current');
		$(this).addClass('current');	
	});	
		
	$('.pane').hover(
		function() {
			clearInterval(auto);
		},
		function() {
			clearInterval(auto);
			auto = setInterval('openTab()', 5000);
		}
	);	

});