//array to store IDs of our tabs
var tabs = [];
//index for array
var ind = 0;
//store setInterval reference
var inter;
//change tab and highlight current tab title
function change(stringref){
 //hide the other tabs
 jQuery('.newsrotationtext-container:not(#' + stringref + ')').hide();
 //show proper tab, catch IE6 bug
 if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0")
  jQuery('.newsrotationtext-container#' + stringref).show();
 else
  jQuery('.newsrotationtext-container#' + stringref).fadeIn();
 //clear highlight from previous tab title
 jQuery('.newsrotationnav li.active').removeClass('active');
 //highlight currenttab title
 jQuery('.newsrotationnav li#' + stringref + '_id').addClass('active');
}
function next(){
 //call change to display next tab
 change(tabs[ind++]);
 //if it's the last tab, clear the index
 if(ind >= tabs.length)
  ind = 0;
}
jQuery(document).ready(function(){
 //store all tabs in array
 jQuery(".newsrotationtext-container").map(function(){
  tabs[ind++] = jQuery(this).attr("id");
    })
 //set index to next element to fade
 ind = 1;
 //initialize tabs, display the current tab
 jQuery(".newsrotationtext-container:not(:first)").hide();
 jQuery(".newsrotationtext-container:first").show();
 //highlight the current tab title
 jQuery('.newsrotationnav li:first').addClass('active');
 //handler for clicking on tabs
 jQuery(".newsrotationnav a").click(function(){
  //if tab is clicked, stop rotating
  clearInterval(inter);
  //store reference to clicked tab
  stringref = jQuery(this).attr("href").split('#')[1];
  //display referenced tab
  change(stringref);
  return false;
 });

//start rotating tabs
if (tabs.length > 1) {
 inter = setInterval("next()", 6500);
}

});

