/**
 * GamePageHighScoreModule
 * @author Kevin McBriarty
 * Subclass of Module that handles the high scores on the game pages.
 */
function GamePageHighScoreModule()
{
    /** name of this module */
    this._name = GamePageHighScoreModule.NAME;

    this._game = null;

    this._userId = null;
    this._uuid = null;

    this._cont = null;

    this.initialize = function() {
        this._cont = $("#gamePgHsMod");
        this._userId = this._page.getLoggedInUserId();
        this._uuid = this._page.getLoggedInUserUuid();

       var moduleEveryone = new HighScoresModule(this._game, HighScoresModule.MODE_GAME_PAGE_EVERYONE);
            this._page.registerModule(moduleEveryone);
            moduleEveryone.setUuid(this._uuid);
            moduleEveryone.initialize();


        this._cont.find(".tab_links a").bind("click",this,function(e){
            e.preventDefault();
            var showDiv = $(this).attr("tabname");
            var module = e.data;
            module._cont.find(".mod_main:visible").hide();
            module._cont.find(".mod_main[divname="+showDiv+"]").show();
            
        })
         var _inviteRequest = bindContext(this,function(e){
             e.preventDefault();
             var gameInviteModule = this._page.getModule("GameInviteModule");
             gameInviteModule.setUserId(this._userId);
             gameInviteModule.setGameInfo(this._game.id, this._game.name);
             gameInviteModule.showInputDialog();
         })
         this._cont.find(".gamePgInvite").live("click", _inviteRequest);

        /* Check for non-logged in user */
        if (!this._userId){
           this._cont.find(".mod_main").hide();
           this._cont.find("#everyoneScores").show();
           this._cont.find(".button_highScores").html("SIGN IN").removeClass("gamePgInvite");
           this._cont.find(".mod_bottom").html("<a href=''>Invite Friends</a><br class='clearFloat'/>");
           this._cont.find(".button_highScores,.mod_bottom a,.tab_links a[tabname=friends]").unbind().bind("click",this,function(e){
               e.preventDefault();
               var module = e.data;
               module._callLogin("Log in to see your friends' scores.");
            })
        }else{ //Load friends when logged in
            var moduleFriends = new HighScoresModule(this._game, HighScoresModule.MODE_GAME_PAGE_FRIENDS);
            this._page.registerModule(moduleFriends);
            moduleFriends.setUuid(this._uuid);
            moduleFriends.initialize(); 
        }

     }

    this.setGame = function(game){
       this._game = game;
    }
    this._callLogin = function(headtext){
        if (headtext){
            var args = {"title": headtext,"css_class":"login highlight"};
        }else{
            var args = { "title" : "Log In" };
        }
        ag.widget.user.LoginPopup.showPopup(args);
    }
}

GamePageHighScoreModule.NAME = "GamePageHighScoreModule";

 /** External leaderboard refresh helper method **/
GamePageHighScoreModule.refreshLeaderBoard = function (gameId){
      g_page.getModule("HighScoresModule_MODE_GAME_PAGE_FRIENDS_"+gameId).makeLeaderBoardReq();
      g_page.getModule("HighScoresModule_MODE_GAME_PAGE_EVERYONE_"+gameId).makeLeaderBoardReq();
};
GamePageHighScoreModule.prototype = new Module();








