var currenttab = "btn_newbooks";
var imgPause = "<img src='images/Permanent/btn_pause.gif' width='33' height='32' alt='Pause' />";
var imgPlay = "<img src='images/Permanent/btn_play.gif' width='33' height='32' alt='Play' />";

var pauseTme = 7000;
  
  
  $(document).ready(function(){
 
  // Tabs
  
  $("#tabBtn").html(imgPause);
	
	$("#tabBtn").toggle(
	  function () {
		$(this).html(imgPlay);
		pauseRot();
	  },
	  function () {
		$(this).html(imgPause);
		playRot();
	  }
	);

   
 	var tabContainers = $('div.tabs > div');  
	var $curntTab;
	$('div.tabs span.tabNavigation a').click(function () {  
		tabContainers.hide().filter(this.hash).show();
		$('div.tabs span.tabNavigation a').removeClass('selected');
		$(this).addClass('selected'); 
		$curntTab = $(this).id;
		restTabs();
		var src =  $(this).children().attr("src").replace("_off", "_on");   
		$(this).children().attr("src", src); 
		return false;  
	}).filter(':first').click();
	
  $("img.rotatorimg")       
   		.mouseover(function() {     
			if($(this).parent().attr("class") != "selected") {
				var src = $(this).attr("src").replace("_off", "_on");         
				$(this).attr("src", src);    
			}
		})        
		.mouseout(function() {   
			if($(this).parent().attr("class") != "selected") {
				var src = $(this).attr("src").replace("_on", "_off");         
				$(this).attr("src", src);    
			}
		});
		
		$(document).everyTime(pauseTme, "showNxtLnk", function(i) {
 			shwNxt();
		});


		
		
  });
  
  // Tab Functions 
  
  function restTabs() {
		 $("img.rotatorimg").each(function(i){
   			var src = $(this).attr("src").replace("_on", "_off");  
			$(this).attr("src", src);   
 	});
}

var tabLinks = new Array("newbookslnk", "newmovieslnk", "newmusiclnk", "patronperkslnk");

var cn = 0;

function shwNxt() {
	cn++;
	if (cn > 3) {
		cn = 0
	}
	$("#" + tabLinks[cn]).click();
}

function pauseRot() {
	$(document).stopTime();
}

function playRot() {
	updateCN();
	shwNxt();
	$(document).everyTime(pauseTme, "showNxtLnk", function(i) {
 		shwNxt();
	});
}

function updateCN() {
	$("img.rotatorimg").each(function(i){
		if($(this).parent().attr("class") == "selected") {
			cSel = $(this).parent().attr("id");
		}
	});
	switch(cSel) {
		case "newbookslnk":
			cn=0;
			break;
		case "newmovieslnk":
			cn=1;
			break;
		case "newmusiclnk":
			cn=2;
			break;
		case "patronperkslnk":
			cn=3;
			break;
	}

}
  
