﻿//=====================================================================================
// Author: Matt Louderback   12/18/2009
// Purpose: 
//    This is used to implementing the client side tabbing functionallity of the MDM home page 
//    tabbed news stories web part.
//
//=====================================================================================


    //------------------------------------------------------------------------------------
    // TabsController
    // - firstTabSearch : the jQuery sear4ch string for the tab that is active on startup
    // - firstPageSearch: the jQuery search string for the page that is active on statup
    // - tabStyleDeltaActiveIn: the style delta for each tab button when it becomes active
    // - tabStyleDeltaInactiveIn: the style delta for each tab button when it becomes inactive
    //
    function TabsController(firstTabSearch, firstPageSearch, tabStyleDeltaActiveIn, tabStyleDeltaInactiveIn)
    {
        this.activeTabSearch  = firstTabSearch;
        this.activePageSearch = firstPageSearch;
        this.tabStyleDeltaActive  = tabStyleDeltaActiveIn;
        this.tabStyleDeltaInactive  = tabStyleDeltaInactiveIn;
    }
    
    TabsController.prototype = 
    {
        //--------------------------------------------------------
        // onTabClicked()
        // - tabSearch:  the jQuery search string for the tab that is to become active
        // - pageSearch: the jQuery search string for the page that is to become active
        //
        onTabClicked: function(tabSearch, pageSearch )
        {
          
            if (this.activeTabSearch == tabSearch)
            {
                return;
            }
            
            if (this.activePageSearch.length > 0)
            {
                this.hidePage(this.activePageSearch);
            }

            // Show the new page.
            this.showPage(pageSearch);
            
            if (this.activeTabSearch.length > 0)
            {
                this.deactivateTab(this.activeTabSearch);
            }
            
            // Change the new active tab's style to look active.
            this.activateTab(tabSearch);
            
            this.activeTabSearch = tabSearch;
            this.activePageSearch = pageSearch;
        },
        
        //--------------------------------------------------------
        // activateTab()
        // - tabDivSearch:  the jQuery search string for the tab that is to become active
        //
        activateTab: function(tabDivSearch)
        {
           // $(tabDivSearch).css('background-color','#F0F0F0');
           // $(tabDivSearch).css('border-top-color','#990002');

            if (this.tabStyleDeltaActive != null)
            {
                $(tabDivSearch).css(this.tabStyleDeltaActive);
            }
        },
        
        //--------------------------------------------------------
        // deactivateTab()
        // - tabDivSearch:  the jQuery search string for the tab that is to become inactive
        //
        deactivateTab: function(tabDivSearch)
        {
            // Change its style to an inactive tab's look
          //  $(tabDivSearch).css('background-color','#E7E1D5');
          //  $(tabDivSearch).css('border-top-color','#666666');
          
            if (this.tabStyleDeltaActive != null)
            {
                $(tabDivSearch).css(this.tabStyleDeltaInactive);
            }
        },

        //--------------------------------------------------------
        // showPage()
        // - pageDivSearch:  the jQuery search string for the page that is to be shown
        //
        showPage: function(pageDivSearch)
        {
            $(pageDivSearch).show(null,null);
        },
        
        //--------------------------------------------------------
        // hidePage()
        // - pageDivSearch:  the jQuery search string for the page that is to be hidden
        //
        hidePage: function(pageDivSearch)
        {
            $(pageDivSearch).hide(null,null);
        }
    
    }

