// JavaScript Document

/*************************************
    SIDEBAR TABS PANEL
**************************************/   
var g_selectedSideBarTabBtn = null;
var g_tabBtnColorSidebar = "#3399CC";
function setupSidebarTabsPanel()
{
    $j(".sidebarTabsContainer").each(
        function()
        {
            // get number of tab buttons
            var tabsList = $j(this).find(".btn");

            // for every tab button check existing of default tab marker
            for(var i = 0; i < tabsList.length; i++)
            {
               var btn = $j(this).find(".btn:eq("+i+")");
               var defaultTab = $j(btn).find(".default");
               // if tab is default set it to visibile and highlight the button
               if(defaultTab.length != 0)
               {
                    $j(btn).each(function(){g_selectedSideBarTabBtn = this;});
                    var tabID = $j(btn).find(".source").text();
                    $j(tabID).css("visibility", "visible").css("top", 0);
                    $j(btn).css("background-color", g_tabBtnColorSidebar);
                    break;
               }
            }
            
    $j(this).find(".btn").click(
        function()
        {
             if(g_selectedSideBarTabBtn == this)
             {
                return;
             } 
             if(g_selectedSideBarTabBtn != null)
             {
                $j(g_selectedSideBarTabBtn).css("background-color", "#000");
             }
             var oldSource = $j(g_selectedSideBarTabBtn).find(".source").text();
             g_selectedSideBarTabBtn = this;
             $j(this).css("background-color", g_tabBtnColorSidebar);
             
             $j(oldSource).animate({opacity: 0.0}, 200, 
                function()
                {
                    $j(this).css("visibility", "hidden");
                    var tabSource = $j(g_selectedSideBarTabBtn).find(".source").text();
                    $j(tabSource)
                        .css("opacity", 0.0)
                        .css("top", 0)
                        .css("visibility", "visible")
                        .animate({opacity: 1.0}, 400); 
                }
             );
        }
    );
   
    $j(this).find(".btn").hover(
        function()
        {
            if(this != g_selectedSideBarTabBtn)
            {
                $j(this).css("background-color", g_tabBtnColorSidebar);
            }
        },
        function()
        {
            if(this != g_selectedSideBarTabBtn)
            {
                $j(this).css("background-color", "#000000");
            }
        }
    );
            
        }
    );
} // end of function setupSidebarTabsPanel

