var logger = new Logger( Logger.info );
var tabBar;
var slideShow;

$(
    function()
    {
        // Initialize the tab bar.
        var tabBarOptions =
            {
                // Defines each tab in the tab bar. In particular, the URL we fetch the tab's
                // contents from and handlers that we execute when we display and remove the
                // tab's contents.
                tabs:
                {
                    tabHome:
                    {
                        defaultSubTab: "subTabHomeWelcome"
                    },
                        subTabHomeWelcome:
                        {
                            // Where we get our tab's contents on the server
                            url: "home-welcome.html",
                            // url: "css-test.html",
                            handlers:
                            {
                                // Called after we load the tab
                                load: function( tabBar, tabData )
                                    {
                                        $( "#otherPageHeader" ).hide( 0 );

                                        // If the slide show/mission statement area is not visible then display it.
                                        var homePageHeader = $( "#homePageHeader" );
                                        if (homePageHeader.css( "display" ) == "none")
                                        {
                                            homePageHeader.show( 0 );
                                            slideShow.start();
                                        }
                                    },
                                // Called when the tab is going away.
                                unload: function( tabBar, tabData )
                                    {
//                                        $( "#homePageHeader" ).hide(
//                                            0,
//                                            function() { $( "#otherPageHeader" ).show( 0 ); }
//                                        );
                                        $( "#homePageHeader" ).hide( 0 );
                                        $( "#otherPageHeader" ).show( 0 ); 
                                        slideShow.stop();
                                    }
                            }
                        },
                        subTabHomeContactUs:
                        {
                            url: "home-contact-us.html"
                        },
                        subTabHomeFrJerry:
                        {
                            url: "home-fr-jerry.html"
                        },
                    // This tab exists only in the phase one site
                    tabHomePhase1:
                    {
                        url: "home-welcome.html",
                        handlers:
                        {
                            // Called after we load the tab
                            load: function( tabBar, tabData )
                                {
                                    $( "#otherPageHeader" ).hide( 0 );

                                    // If the slide show/mission statement area is not visible then display it.
                                    var homePageHeader = $( "#homePageHeader" );
                                    if (homePageHeader.css( "display" ) == "none")
                                    {
                                        homePageHeader.show( 0 );
                                        slideShow.start();
                                    }
                                },
                            // Called when the tab is going away.
                            unload: function( tabBar, tabData )
                                {
//                                        $( "#homePageHeader" ).hide(
//                                            0,
//                                            function() { $( "#otherPageHeader" ).show( 0 ); }
//                                        );
                                    $( "#homePageHeader" ).hide( 0 );
                                    $( "#otherPageHeader" ).show( 0 );
                                    slideShow.stop();
                                }
                        }
                    },
                    // This tab exists only in the phase one site
                    tabFrJerry:
                    {
                        url: "home-fr-jerry.html"
                    },
                    // This tab exists only in the phase one site
                    tabContactUs:
                    {
                        url: "home-contact-us-simple.html"
                    },
                    tabMasses:
                    {
                        url: "masses.html"
                    },
                    tabSacraments:
                    {
                        defaultSubTab: "subTabSacBaptism"
                    },
                        subTabSacBaptism:
                        {
                            url: "sacraments-baptism.html"
                        },
                        subTabSacFirstEucharist:
                        {
                            url: "sacraments-first-eucharist.html"
                        },
                        subTabSacConfirmation:
                        {
                            url: "sacraments-confirmation.html"
                        },
                        subTabSacRCIA:
                        {
                            url: "sacraments-rcia.html"
                        },
                        subTabSacMarriage:
                        {
                            url: "sacraments-marriage.html"
                        },
                        subTabSacReconciliation:
                        {
                            url: "sacraments-reconciliation.html"
                        },
                        subTabSacAnointing:
                        {
                            url: "sacraments-anointing.html"
                        },
                    tabMinistries:
                    {
                        defaultSubTab: "subTabMinLiturgy"
                    },
                        subTabMinLiturgy:
                        {
                            url: "ministries-liturgy.html"
                        },
                        subTabMinMusic:
                        {
                            url: "ministries-music.html"
                        },
                        subTabMinSick:
                        {
                            url: "ministries-sick.html"
                        },
                        subTabMinSVdP:
                        {
                            url: "ministries-st-vincent-de-paul.html"
                        },
                        subTabMinOutreach:
                        {
                            url: "ministries-outreach.html"
                        },
                    tabPrograms:
                    {
                        defaultSubTab: "subTabPgmRelEd"
                    },
                        subTabPgmRelEd:
                        {
                            url: "programs-religous-ed.html"
                        },
                        subTabPgmYouth:
                        {
                            url: "programs-youth.html"
                        },
                        subTabPgmAltarSoc:
                        {
                            url: "programs-altar-society.html"
                        },
                        subTabPgmCharismatic:
                        {
                            url: "programs-charismatic-prayer.html"
                        },
                        subTabPgmEngaged:
                        {
                            url: "programs-engaged-encounter.html"
                        },
                        subTabPgmMarriage:
                        {
                            url: "programs-marriage-encounter.html"
                        },
                        subTabPgmRespectLife:
                        {
                            url: "programs-respect-life.html"
                        },
                        subTabPgmRetrouvaille:
                        {
                            url: "programs-retrouvaille.html"
                        },
                    tabEvents:
                    {
                        url: "events.html"
                    },
                    tabCommunity:
                    {
                        url: "community.html"
                    },
                    tabCalendarP1:
                    {
                        url: "calendar.html"
                    },
                    tabSchedulesP1:
                    {
                        url: "ministry-schedules.html"
                    },
                    tabCalendar:
                    {
                        defaultSubTab: "subTabCalParish"
                    },
                        subTabCalParish:
                            {
                                url: "calendar.html"
                            },
                        subTabCalMinistries:
                            {
                                url: "ministry-schedules.html"
                            },
                    tabCommittees:
                    {
                        url: "committees.html"
                    }
                }
            };
        tabBar = new TabBar( "#mainTabBar", "#content", tabBarOptions );
    }
);

function imageLoaded()
{
    var headerImage = $( ".headerImage" );
    var headerImageBuffer = $( ".headerImageBuffer" );

    headerImage[0].onload = null;

    slideShow = new SlideShow(
        ".headerImage", ".headerImageBuffer",
        [
            "images/slide_show/Altar_and_Crucifix.jpg",
            "images/slide_show/Bishop_Garcia_Confirmation.jpg",
            "images/slide_show/Carolyn_and_Heidi.jpg",
            "images/slide_show/crucifix.gif"
        ]
    );
    slideShow.start();

    // Stop after one minute.
    setTimeout(
        function()
        {
            slideShow.stop();
        },
        60 * 1000
    );
}

