﻿var heroTab_timey;
var heroTab_buttons;
var heroTab_scrollIndex = 0;

var heroTab_tabPopWidth = '52px';
var heroTab_tabWidth = '42px';

function heroTab_advanceTo(tab,index)
{
    var tabList = $("div#tabContainer ul#tabs");
    
    var selected = $("div#tabContainer div.tabBar .tab.selected");
    selected.removeClass('selected').animate({width:heroTab_tabWidth},200);
    
    $(tab).addClass('selected');
    
    tabList.find('li.selected').slideUp();
    tabList.find('li.selected').removeClass('selected');
    
    tabList.find('li#tab' + index).slideDown();
    tabList.find('li#tab' + index).addClass('selected');
}

function heroTab_autoScroll()
{
    if(heroTab_scrollIndex < heroTab_buttons.length)
    {
        if(!$(heroTab_buttons[heroTab_scrollIndex]).hasClass('selected'))
            heroTab_advanceTo(heroTab_buttons[heroTab_scrollIndex],heroTab_scrollIndex);
            
        heroTab_scrollIndex++;
        
        heroTab_timey = setTimeout("heroTab_autoScroll()",5000);
    }
}

$(document).ready(function(){
    
    var tabButtons = $("div#tabContainer div.tabBar .tab");
    var tabList = $("div#tabContainer ul#tabs");
    var tabContent = $("div#tabContainer div#tabContent");
    
    if (tabButtons.length > 0)
    {
        heroTab_buttons = tabButtons;
        
        tabButtons.each(function(index) 
        {
            var tab = $(this);
            
            tab.mouseenter(function()
            {
                if(!$(this).hasClass('selected'))
                    $(this).stop().animate({width:heroTab_tabPopWidth},200);
            }).mouseleave(function()
            {
                if(!$(this).hasClass('selected'))
                    $(this).stop().animate({width:heroTab_tabWidth},200);
            });
            
            tab.click(function()
            {
                clearTimeout(heroTab_timey);
                
                if(!tabList.find('li#tab' + index).hasClass('selected'))
                {
                    heroTab_advanceTo($(this),index);
                }
            });
        });
        
        heroTab_autoScroll();
    }
    
    
    
    
    
});
