﻿// GMA = Game Menu Area
function GMA(i) {
    var e = $(i);
    this.actionDiv = $(i + "_panAction");
    this.menuDiv = $(i + "_panMenu");
    this.gameDiv = $(i + "_panGame");
    this.movieDiv = $(i + "_panMovieContainer");
    this.gameKeyField = $(i + "_tbGameKey");
    this.gameModeField = $(i + "_tbGameMode");
    this.modeFunIndicator = $(i + "_lblFun");
    this.modeButtonReal = $(i + "_btnReal");
    this.modeButtonFun = $(i + "_btnFun");
    
    this.bannerDiv = $("#casinobanner");
};
GMA.prototype.Play = function(key) {
    if (this.gameKeyField.val() != "") {
        try {
            (new TrackControl()).NotifyGameUnloaded(this.gameKeyField.val(), this.gameModeField.val() == "real");
        }
        catch (e) { };
    }

    hideModeChooser(); hideSubMenu();

    this.DisplayButtons();
    this.menuDiv.slideUp();
    $('#gametabs').slideUp();
    this.bannerDiv.slideUp();
    this.gameKeyField.val(key);
    var mode = this.gameModeField.val();
    var movieDiv = this.movieDiv;

    wait(movieDiv);
    this.movieDiv.hide();
    this.gameDiv.show();
    this.movieDiv.fadeIn();

    var url = '/opSys/FullScreenGame.aspx?key=' + key + '&mode=' + mode + '&needcontrols=false&lang=' + g_language;
    this.gameKeyField.val(key);
    $('#ifmGame').attr('src', url);
   
    ready();
    movieDiv.css("opacity", "1");
    try {
        (new TrackControl()).NotifyGameLoaded(key, mode == "real");
    }
    catch (e) { };

    return false;
};

GMA.prototype.PlayInFullScreen = function(key) {

    try {
        (new TrackControl()).NotifyGameLoaded(key, this.gameModeField.val() == "real");
    }
    catch (e) { };

    if (key == null) key = this.gameKeyField.val();
    var url = '/opSys/FullScreenGame.aspx?key=' + key + "&mode=" + this.gameModeField.val() + '&needcontrols=false&lang=' + g_language;
    var wnd = window.open(url, "_blank", "fullscreen=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0");
    if (wnd == null) {
        alert("The popup window is blocked, please adjust your browser setting to allow popups in this site.");
    }
    return false;
};

GMA.prototype.OpenGameRules = function() {

    var url = '/opSys/GameRules.ashx?gameid=' + this.gameKeyField.val() + '&lang=' + g_language;
    var wnd = window.open(url, "_blank", "fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,width=450, height=500");
    if (wnd == null) {
        alert("The popup window is blocked, please adjust your browser setting to allow popups in this site.");
    }
    return false;
};
GMA.prototype.ModeReal = function() {
    this.gameModeField.val("real");
    if (this.gameKeyField.val() != "") {
        if (openGameInModalWindow == "false") {
            this.Play(this.gameKeyField.val());
        } else {
            this.PlayInModalWindow(this.gameKeyField.val());
        }
    }
    
    return false;
};
GMA.prototype.ModeFun = function() {
    this.gameModeField.val("fun");
    if (this.gameKeyField.val() != "") {
        if (openGameInModalWindow == "false") {
            this.Play(this.gameKeyField.val());
        }
        else {
            this.PlayInModalWindow(this.gameKeyField.val());
        }
    }
    
    return false;
};
GMA.prototype.ShowMenu = function() {
    if (this.gameKeyField.val() != "") {
        try {
            (new TrackControl()).NotifyGameUnloaded(this.gameKeyField.val(), this.gameModeField.val() == "real");
        }
        catch (e) { };
    }

    $('#ifmGame').attr('src', '');
    this.gameDiv.slideUp();
    this.menuDiv.slideDown();
    $('#gametabs').slideDown();
    this.bannerDiv.slideDown();

    var real = this.gameModeField.val() == "real";
    if (real) {
        try {
            setTimeout('top.StartLoadBalances(true)', 5000);
            self.fpp.onbtnRefreshClicked();
        } catch (e) { }
    }

    return false;
};
GMA.prototype.DisplayButtons = function() {
    var real = this.gameModeField.val() == "real";
    this.modeButtonReal = $("#" + gma.modeButtonReal.attr("id"));
    this.modeButtonFun = $("#" + gma.modeButtonFun.attr("id"));
    if (real) {
        this.modeButtonReal.hide();
        this.modeButtonFun.show();
        this.modeFunIndicator.hide();
    }
    else {
        this.modeButtonReal.show();
        this.modeButtonFun.hide();
        this.modeFunIndicator.show();

    }
};
function dbug(m) {
    var w = $("#dbug");
    w.append("<div>" + m + "</div>");
}

if (Sys && Sys.Application) {
    Sys.Application.notifyScriptLoaded();
}
