$(document).ready()
{
    
    ///////////////
    // SLIDESHOW //
    ///////////////
    
    var slideshow = $("#slideshow");
    
    /*
    slideshow.find(".article").each(function(br)
    {
        
    })
    */
    
    var slideshow_change = function(nr)
    {
        //Auto change
        if(nr == 0)
        {
            var current_tab = $("#slideshow #slideshow_tabs .selected");
            var current_tab_nr = current_tab.html();
            
            //alert($("#slideshow .article").length)
            
            
            if(current_tab_nr >= $("#slideshow .article").length)
                current_tab_nr = 1;
            else
                current_tab_nr++;
            
            nr = current_tab_nr;
            
            current_tab_nr--;
            
            current_tab.removeClass("selected");
            $("#slideshow .#slideshow_tabs a:eq("+current_tab_nr+")").addClass("selected");
            
            if($.browser.msie && $.browser.version == 6)
            {
                current_tab.css({ "background-position" : "0 -48px" })
                $("#slideshow .#slideshow_tabs a:eq("+current_tab_nr+")").css({ "background-position" : "" })
            }
            
            
        }
        
        if( $("#slideshow .article:animated").size()==0 )
        {
            //eq je 0 based, a u tabovima imam br taba 1 based
            nr--;
        
            var opened_tab = $("#slideshow .article:eq("+ nr + ")");
            var closed_tab = $("#slideshow .active");
        
            opened_tab.css({ "z-index" : "7" });
        
            closed_tab.fadeOut(500, function()
            {
                closed_tab.removeClass("active").css({"display" : "block" });
                opened_tab.addClass("active").css({ "z-index" : "" });
            })
        }
    }
    
    
    var slideshow_tabs = $("#slideshow #slideshow_tabs");
    slideshow_tabs.find("a").each(function()
    {
        $(this).click(function()
        {
            if( !$(this).hasClass('selected') &&  $("#slideshow .article:animated").size()==0 )
            {
                var s_sel_tab = slideshow_tabs.find(".selected").removeClass("selected");
                $(this).addClass("selected");
                
                if($.browser.msie && $.browser.version == 6)
                {
                    s_sel_tab.css({ "background-position" : "0 -48px" })
                    $(this).css({ "background-position" : "" })
                }
                
                //console.log($(this).html())       
                slideshow_change($(this).html());
            }
            return false;
            
            
        })
    })
    
    
    var intervalLength = 5000;
    
    var slideshow_interval = setInterval("slideshow_change(0)", intervalLength)
    
    $("#slideshow").mouseover(function()
    {
        clearInterval(slideshow_interval);
    }).mouseout(function()
    {
        slideshow_interval = setInterval("slideshow_change(0)", intervalLength)
    });
    
    
    
    
    
    //////////////////
    // NOVOSTI TABS //
    //////////////////
    
    var tabs_pagination = $("#main .section.tabs .tabs_pagination");
    tabs_pagination.find("a").bind('click', function(){
        
    var section_tabs = $("#main .section.tabs");
    
        if( !$(this).hasClass('active') && (section_tabs.find('.article:animated').size() == 0 ) )
        {   
            //Promjena aktivne stranice
            tabs_pagination.find('a.active').removeClass('active');
            $(this).addClass('active');
            
            var nr = $(this).html();
            
            
            section_tabs.find(".article.active").fadeOut(300, function(){
                $(this).css({ "display" : "block" , "opacity" : "1" , "top" : "-100px" });
                section_tabs.find(".article:eq(" + (nr-1) + ")").css({"top" : "0", "display" : "none"}).fadeIn(300).addClass('active');
            });
            //tabs_pagination.find(".article:eq(" + (nr-1) + ")").;
            
        }
        return false;
    })
    
    
    
}
