if(!this.BLUE) {
    BLUE = {};
}
BLUE.schedule = (function() {
    return {
        scoreboardPage : '',
        
        load: function()
        {
            //grab the action for the selectWeek form.
            //This action represents the master scoreboard page
            BLUE.schedule.scoreboardPage = jQuery('#selectWeek').attr('action');
            
            //load the scoreboard from the master scoreboard page
            jQuery("#scoreboard").load(BLUE.schedule.scoreboardPage + "?timestamp=" + BLUE.schedule.getTimeStamp() + " div.scoreboard", function(){
                //only set up the select handler once we have loaded the scoreboard
                BLUE.schedule.setHandlers();
            });
        },
        
        setHandlers: function()
        {
            //bind the change event for the select week options
            jQuery('#selectWeekOptions').bind('change', function(e){
                BLUE.schedule.refreshScoreboard();
            });

            jQuery('#scheduleRefresh').show().bind('click', function(){
                BLUE.schedule.refreshScoreboard(); 
                return false;
            });
        },

        refreshScoreboard : function()
        {
            //grab the selected value and parse to an Int
            var week = parseInt(jQuery('#selectWeekOptions :selected').val(), 10);   
            
            //load the scoreboard section of the master
            //scoreboard page, passing in the week number             
            jQuery("#scoreboard").load(BLUE.schedule.scoreboardPage + "?week=" + week + "&timestamp=" + BLUE.schedule.getTimeStamp() + " div.scoreboard");
        },

        getTimeStamp: function()
        {
            return new Date().getTime();
        }
    };
})();

jQuery(document).ready(function() {
    BLUE.schedule.load();
});

