function Lobby() {

    var lobbyFlasfUrl, lobbyFlasfWidth, tourneyLobbyFlashUrl, lobbyFlasfHeight,
            sessionId, resizable = 0, scrollbars = 0, testLoginUrl, notLoggedUrl;

    Lobby.prototype.init = function (_lobbyUrl, _tourneyUrl, _sessionId, _width,
                                     _height, _resizable, _scrollbars, _testLoginUrl, _notLoggedUrl) {
        lobbyFlasfUrl = _lobbyUrl;
        tourneyLobbyFlashUrl = _tourneyUrl;
        lobbyFlasfHeight = _height;
        lobbyFlasfWidth = _width;
        sessionId = _sessionId;
        resizable = _resizable;
        scrollbars = _scrollbars;
        notLoggedUrl = (_notLoggedUrl && _notLoggedUrl != '') ? _notLoggedUrl : '/login?reason=login_error';
        testLoginUrl = (_testLoginUrl && _testLoginUrl != '') ? _testLoginUrl : '/testxml/casino/index';
    },Lobby.prototype.openGameWindow = function (_id, url, params) {
	    var gameWin;
    	try {
        var winName = 'a_' + sessionId.replace(/-/g, '_') + '_' +
                _id.replace(/[^\w]/g, '_');
        gameWin = window.open("", winName, params);
        if (! gameWin || ! gameWin.document.getElementById('flash_container')) {
            gameWin = window.open(url, winName, params);
        }
        if (gameWin)gameWin.focus();
        } catch(e) {
        }
        return gameWin;
    },Lobby.prototype.openPokerLobby = function () {
        return this.openGameWindow("PokerLobby", lobbyFlasfUrl, "width=" +
                lobbyFlasfWidth + ",height=" + lobbyFlasfHeight +
                ",menubar=0,toolbar=0,status=0,resizable=" + resizable +
                ",scrollbars=" + scrollbars + ",fullscreen=0");
    },Lobby.prototype.openTournamentLobby = function (tournamentId) {
        return this.openGameWindow(tournamentId, tourneyLobbyFlashUrl +
                "?TOURNAMENTID=" + tournamentId, "width=" +
                lobbyFlasfWidth + ",height=" + lobbyFlasfHeight +
                ",menubar=0,toolbar=0,status=0,resizable=" + resizable +
                ",scrollbars=" + scrollbars + ",fullscreen=0");
    },Lobby.prototype.checkUserSessionAndOpenHistoryWin = function (tournamentId) {
        var instance = this;
        $.ajax({
            url: testLoginUrl,
            cache: false,
            async: false,
            dataType: 'xml',
            success: function(data) {
                var $dom = $(data);
                if ($dom.find('LOGGEDIN').length > 0) {
                    instance.openTournamentLobby(tournamentId);
                } else {
                    window.location = '/login';
                }
            }
        });
    },Lobby.prototype.checkUserSessionAndOpenWin = function () {
        var instance = this;
        $.ajax({
            url: testLoginUrl,
            cache: false,
            async: false,
            dataType: 'xml',
            success: function(data) {
                var $dom = $(data);
                if ($dom.find('LOGGEDIN').length > 0) {
                    instance.openPokerLobby();
                } else {
                    window.location = notLoggedUrl;
                }
            },
            error: function(a,b,c) {
            	alert(c)
            }
        });
    }
}

var lobby = new Lobby();

if (window.com == null) {
    window.com ={};
}
if (window.com.intrice == null) {
    window.com.intrice ={};
}

document.getOpencmsObject = function (objName) {
    if('opencms' in document && objName in document['opencms']){
        return document['opencms'][objName];
    }
    return {};
};
