﻿var Spotlight = 
{
    TIMEOUT: 10000,
    
    init: function()
    {            
        var tabs = jQuery("#spotlight").tabs(
        {
            select: function(event, ui) { Spotlight.styleSelected(ui.tab); },
            fx: { opacity: "toggle" }
        });
        
        var interval = Spotlight.startInterval(tabs);
        jQuery("#spotlight ul li a").click(function() { clearInterval(interval); this.blur(); });
    },
    
    startInterval: function(tabs)
    {
        return setInterval(function()
        {
            var selected = tabs.tabs('option', 'selected');
            var next = selected + 1;
              
            if (next >= Spotlight.count())
                tabs.tabs('select', 0);
            else
                tabs.tabs('select', next);
        }, Spotlight.TIMEOUT);
    },
    
    styleSelected: function(tab)
    {
        jQuery("#spotlight ul li a").removeClass("selected");
        jQuery(tab).addClass("selected");
    },
    
    count: function()
    {
        return jQuery("#spotlight .spotlight-content").length;
    }
};

jQuery(Spotlight.init);
