function kickToInterupted(jid, param2)
{
	var id = getGameByJid(jid);
	OpenGame(id, '_'+param2);
	setTimeout('try{window.close();}catch(ex){}', 1000);
}

function openExchanger()
{
	var u = getBaseUrl()+'#exchange';
//	if (window.opener)
//	{
//		window.opener.document.location = u;
//		window.opener.focus();
//	}
//	else
//	{
		window.open(u, 'gamesMain', '').focus();
//	}
}
function exitCasino()
{
	window.close();
}

function openHistory()
{
	var u = getBaseUrl()+'#history';
//	if (window.opener)
//	{
//		window.opener.document.location = u;
//		window.opener.focus();
//	}
//	else
//	{
		window.open(u, 'gamesMain', '').focus();
//	}
}

var _gamesBaseUrl = '';
var _gamesLanguage = '';
function getBaseUrl()
{
	if ('' != _gamesBaseUrl)
	{
		return _gamesBaseUrl;
	}
	var rx = new RegExp('^/?((([a-z]{2})/)?([^/]+))?/','gi');
	var m = rx.exec(document.location.pathname);

	if (null != m)
	{
		_gamesBaseUrl = m[0];
		_gamesLanguage = m[3];
	}
	else
	{
		_gamesBaseUrl = '/games/';
		_gamesBaseUrl = 'en';
	}
	return _gamesBaseUrl;
}
//getBaseUrl();
//alert(getBaseUrl());

function Game()
{
}
Game.prototype = {
	name:'',
	size:{w:0,h:0},
	caption:'',
	path:'',
	jid:'',
	real: {
		_vip:{b:0,t:''},
		_comfort:{b:0,t:'0'},
		_public:{b:0,t:'0'}
	}
};
//var _gCodes = [
//		"hilo",
//		"deck selecta",
//		"roulette",
//		"blackjack",
//		"oasis poker",
//		"videopoker(jacks or better)",
//		"videopoker(tens or better)",
//		"videopoker(aces and faces)",
//		"videopoker(deuces wild)",
//		"videopoker(joker-poker)",
//		"western slot",
//		"sea world slot",
//		"craps",
//		"wheel",
//		"baccarat"
//];
/**
 * возвращает номер игрушки по строке-коду который сообщает игра
 * @param code String код который приходит из игры
 */
function getGameByJid(jid)
{
	if (null == jid || '' == jid)
	{
		return 0;
	}
	jid = jid.toLowerCase();
	for(var i in games)
	{
		var g = games[i];
		if ('object' == typeof(g) && 'undefined' != typeof (g.jid) && g.jid == jid)
		{
			return i;
		}
	}
	return 0;
}
/**
 *
 * @param {String} id анчор от ссылки на игру
 * @return {Game} найденна в списке игра или false
 */
function getGame(id)
{
	return games[id];
}
var games = {
	'#super-hi-lo': {
		name:'hi_lo',
		caption:'Super Hi/Lo',
		path:'soft/hilo/HiLo.html',
		jid : "hilo",
		size:{w:760,h:420},
		real:{
			_vip:{b:5,t:'5-150'},
			_comfort:{b:1,t:'1-30'},
			_public:{b:0.1,t:'0.1-3'}
		}
	},
	'#hi-lo':{
		name:'deck_selecta',
		jid : 'deck selecta',
		size:{w:760,h:420},
		caption:'Больше/меньше',
		path:'soft/deck_selecta/DeckSelecta.html',
		real:{
			_vip:{b:5,t:'5-150'},
			_comfort:{b:1,t:'1-30'},
			_public:{b:0.1,t:'0.1-3'}
		}
	},
	'#wheel': {
		name:'wheel',
		jid : 'wheel',
		caption:'Колесо удачи',
		path:'soft/wheel/Wheel.html',
		size:{w:760,h:420},
		real:{
			_vip:{b:5,t:'5-150'},
			_comfort:{b:1,t:'1-30'},
			_public:{b:0.1,t:'0.1-3'}
		}
	},
	'#roulette' : {
		name:'roulette',
		jid:'roulette',
		size:{w:0,h:0},
		caption:'Рулетка',
		path:'tables/roulette/index.html',
		real:{
			_vip:{b:5,t:'5-1000'},
			_comfort:{b:1,t:'1-200'},
			_public:{b:0.1,t:'0.1-20'}
		}
	},
	'#craps' : {
		name:'craps',
		jid:'craps',
		size:{w:0,h:0},
		caption:'Крэпс',
		path:'tables/craps/index.html',
		real:{
			_vip:{b:5,t:'5-1000'},
			_comfort:{b:1,t:'1-200'},
			_public:{b:0.1,t:'0.1-20'}
		}
	},
	'#blackjack' : {
		name:'blackjack',
		jid:'blackjack',
		size:{w:0,h:0},
		caption:'Блэкджек',
		path:'cards/blackjack/index.html',
		real:{
			_vip:{b:10,t:'10-500'},
			_comfort:{b:2,t:'2-100'},
			_public:{b:0.2,t:'0.2-10'}
		}
	},
	'#baccarat' : {
		name:'baccarat',
		jid:'baccarat',
		size:{w:0,h:0},
		caption:'Баккара',
		path:'cards/baccarat/index.html',
		real:{
			_vip:{b:10,t:'10-500'},
			_comfort:{b:2,t:'2-100'},
			_public:{b:0.2,t:'0.2-10'}
		}
	},
	'#oasis' : {
		name:'poker',
		jid:'oasis poker',
		size:{w:0,h:0},
		caption:'Оазис покер',
		path:'cards/poker/index.html',
		real:{
			_vip:{b:5,t:'5-250'},
			_comfort:{b:1,t:'1-50'},
			_public:{b:0.1,t:'0.1-5'}
		}
	},
	"#vpj" : {
		name:'vp_jack_or_better',
		jid:'videopoker(jacks or better)',
		size:{w:0,h:0},
		caption:'Валеты и старше',
		path:'videopokers/classic/jacks_or_better.html',
		real:{
			_vip:{b:5,t:'5-250'},
			_comfort:{b:1,t:'1-50'},
			_public:{b:0.01,t:'0.01-0.5'}
		}
	},
	'#vpt' : {
		name:'vp_10_or_better',
		jid:'videopoker(tens or better)',
		size:{w:0,h:0},
		caption:'Десятки и старше',
		path:'videopokers/classic/tens_or_better.html',
		real:{
			_vip:{b:5,t:'5-250'},
			_comfort:{b:1,t:'1-50'},
			_public:{b:0.01,t:'0.01-0.5'}
		}
	},
	'#vpa' : {
		name:'vp_aces_and_faces',
		jid:'videopoker(aces and faces)',
		size:{w:0,h:0},
		caption:'Тузы и картинки',
		path:'videopokers/classic/aces_and_faces.html',
		real:{
			_vip:{b:5,t:'5-250'},
			_comfort:{b:1,t:'1-50'},
			_public:{b:0.01,t:'0.01-0.5'}
		}
	},
	'#vp2' : {
		name:'vp_deuces_wild',
		jid:'videopoker(deuces wild)',
		size:{w:0,h:0},
		caption:'Дикие двойки',
		path:'videopokers/classic/deuses_wild.html',
		real:{
			_vip:{b:5,t:'5-250'},
			_comfort:{b:1,t:'1-50'},
			_public:{b:0.01,t:'0.01-0.5'}
		}
	},
	'#vpjp' : {
		name:'vp_joker_poker',
		jid:'videopoker(joker-poker)',
		size:{w:0,h:0},
		caption:'Джокер покер',
		path:'videopokers/classic/joker_poker.html',
		real:{
			_vip:{b:5,t:'5-250'},
			_comfort:{b:1,t:'1-50'},
			_public:{b:0.01,t:'0.01-0.5'}
		}
	},
	'#sw' : {
		name:'slot_western',
		jid:'western slot',
		size:{w:0,h:0},
		caption:'Вестерн слот',
		path:'slots/western/index.html',
		real:{
			_vip:{b:0.5,t:'0.5-5'},
			_comfort:{b:0.1,t:'0.1-1'},
			_public:{b:0.01,t:'0.01-0.1'}
		}
	},
	'#ss' : {
		name:'slot_sea',
		jid:'sea world slot',
		size:{w:0,h:0},
		caption:'Морской мир',
		path:'slots/seaworld/index.html',
		real:{
			_vip:{b:0.5,t:'0.5-15'},
			_comfort:{b:0.1,t:'0.1-3'},
			_public:{b:0.01,t:'0.01-0.3'}
		}
	},
	'#deberts' : {
		name:'deberts',
		size:{w:0,h:0},
		caption:'Деберц',
		path:'../mgames/',
		real:null,
		external: true
	},
	'#durak' : {
		name:'durak',
		size:{w:0,h:0},
		caption:'Дурак',
		path:'../mgames/',
		real:null,
		external: true
	}
};
var _lastOpenGameWindow = null;
function _openWin(surl, tb)
{
	var w = parseInt(screen.availWidth * 0.6), h = parseInt(screen.Width * 0.45);
	var x = parseInt((screen.availWidth - w) / 2), y = parseInt((screen.availHeight - h) / 2);
	_lastOpenGameWindow = window.open(surl, 'games_window', 'menubar=0,status=1,resizable=0,top=' + y + ',height=' + h + ',left=' + x + ',width=' +
	                              w + ',location=0,toolbar=0,scrollbars=' + tb + '').focus();
}
/**
 * открывет попап с игрой
 * @param {String} game адрес игры
 * @param {String} mode тип игры demo/real
 * @param {Number} minbet размер минимальной ставки за столом
 * @param {String} table тпа зала public, comfort, vip
 * @param {Number} w ширина окна с игрой, если "0" то вычисл€етс€ автоматом
 * @param {Number} h высота окна с игрой, если "0" то вычисл€етс€ автоматом
 */
function _openGame(game, mode, minbet, table, w, h)
{
	var wurl = '' + game + '?minbet=' + minbet + '&table=' + table + '&mode=' + mode + '';

	if ('undefined' == typeof w || 'undefined' == typeof h || 0 == w + h)
	{
		//        h = parseInt(screen.width * 0.6375);
		//        w = parseInt(screen.width * 0.85);
		h = 715;
		w = 1050;
	}
	wurl += '&w=' + w + '&h=' + h;


	var x = parseInt((screen.width - w) / 2), y = parseInt((screen.height - h) / 4);

	wurl = 'https://'+location.hostname+wurl;
	_lastOpenGameWindow = window.open(wurl, 'pari', 'menubar=0,status=1,resizable=1,top=' + y + ',height=' + h + ',left=' + x + ',width=' + w +
	                          ',location=0,toolbar=0,scrollbars=0').focus();

	if ('undefined' != typeof($))
	{
		$("#gs").dialog('close');
	}
}
/**
 * открывает заданную игру с заданным типаом стола
 * @param {String} gid идентификатор игры
 * @param {String} t тип стола
 */
function OpenGame(gid, t)
{
	var g = getGame(gid);
	//	alert(g + " " + t);
	if (!g) return;
	var mode = 'real';
	var stake = g.real._comfort.b;
	var table = t.substring(1, t.length);
	if ('_demo' == t)
	{
		mode = 'demo';
		table = 'comfort';
	}
	else
	{
		stake = g.real[t].b;
	}
	_openGame(getBaseUrl() + g.path, mode, stake, table, g.size.w, g.size.h);
}
