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 = $("#organic-tabs #explore-nav a").index(clickedTab);
   $("#organic-tabs #explore-nav li a").removeClass("active");
   $("#organic-tabs #explore-nav li a:eq("+thisTab+")").addClass("active");
   $("#all-list-wrap .tabbed-content").fadeOut(0);
   $("#all-list-wrap .tabbed-content:eq("+thisTab+")").fadeIn();
   currentTab = thisTab;
}

function rotateTabs() {
   var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
   openTab($("#organic-tabs #explore-nav li a:eq("+nextTab+")"));
}

$(document).ready(function() {
   numTabs = $("#organic-tabs #explore-nav li a").length;
   $("#organic-tabs #explore-nav li a").click(function() { openTab($(this)); return false; });
   $("#organic-tabs").mouseover(function(){clearInterval(autoRotate)})
   .mouseout(function(){autoRotate = setInterval("rotateTabs()", rotateSpeed)});
   
   $("#organic-tabs #explore-nav li a:eq("+currentTab+")").click()
   $("#organic-tabs").mouseout();
   
});
