var rotateSpeed = 5000; // Milliseconds to wait until switching tabs.
var currentTab = 0; // Set to a different number to start on a different tab.
var numTabs; // These two variables are set on document ready.
var autoRotate;

function openTab(clickedTab) {
   var thisTab = jQuery(".tabbed-box .tabs a").index(clickedTab);
   jQuery(".tabbed-box .tabs a").removeClass("active");
   jQuery(".tabbed-box .tabs a:eq("+thisTab+")").addClass("active");
   jQuery(".tabbed-box .tabbed-content").stop(true,true).hide();
   jQuery(".tabbed-box .tabbed-content:eq("+thisTab+")").stop(true,true).fadeIn(500);
   currentTab = thisTab;
}

function rotateTabs() {
   var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
   openTab(jQuery(".tabbed-box .tabs a:eq("+nextTab+")"));
}

jQuery(document).ready(function() {
   numTabs = jQuery(".tabbed-box .tabs a").length;
   autoRotate = setInterval("rotateTabs()", rotateSpeed);
   jQuery(".tabbed-box .tabs a").hover(function() {openTab($(this)); clearInterval(autoRotate); return false;}, function(){autoRotate = setInterval("rotateTabs()", rotateSpeed)});
   $('.slideshow img').hover(function(){
		clearInterval(autoRotate); return false;
   },function(){
		autoRotate = setInterval("rotateTabs()", rotateSpeed);
   });
	
});

