/* this needs jquery */
/* this needs typo3 config modification for IE: config.prefixLocalAnchors = 0 */

/* tab carousel
------------------------------------------------------------ */
var auto_tab_id = -1;
var auto_tab_timeout = 5000;

$(function() {  
  $(".tab_carousel_tabs li").click(function(event) {
      event.preventDefault();
      
      if (auto_tab_id >= 0) {
          clearTimeout(auto_tab_id);
          $(".tab_carousel").unbind("mouseenter mouseleave");
      }
      
      var $this = $(this);
      if ($this.hasClass("selected")) {
          return false;
      } else {          
          $(".tab_carousel_tabs .selected").removeClass("selected");
          $this.addClass("selected");
          
          $(".tab_carousel_item:visible").fadeOut(400);
          var target = $this.find("a").attr("href");
          $(target).fadeIn(400);
      }
  });
  
  $(".tab_carousel").hover(function() {
      if (auto_tab_id >= 0) {
          clearTimeout(auto_tab_id);
      }
  }, function() {
      auto_tab_id = setTimeout(next_tab, auto_tab_timeout);
  });
  
  auto_tab_id = setTimeout(next_tab, auto_tab_timeout);
});

function next_tab() {
    var $selected_tab = $(".tab_carousel_tabs .selected").removeClass("selected");
    var $selected_item = $(".tab_carousel_item:visible").fadeOut(400);
    if ($selected_tab.hasClass("row_end")) {
        $(".tab_carousel_tabs li:first").addClass("selected");
        $(".tab_carousel_item:first").fadeIn(400);
    } else {
        $selected_tab.next().addClass("selected");
        $selected_item.next().fadeIn(400);
    }    
    
    auto_tab_id = setTimeout(next_tab, auto_tab_timeout);
}
