$(document).ready(function() {
	let gameList = [
		// Sportbook
		{game: 'wbsport', gid: 125},
		{game: 'isport', gid: 11},
		{game: 'ssport', gid: 37},
		{game: 'ssport2g', gid: 37},
		{game: 'sbsport', gid: 103},
		{game: 'flashtech', gid: 107},
		// Poker
		{game: 'balakplay', gid: 38},
		{game: 'p2play', gid: 209},
		{game: 'sukagaming', gid: 192},

		{game: 'tangkas', gid: 3},
		// Slots
		{game: 'slot-pt', gid: 15},
		{game: 'slot-gp', gid: 21},
		{game: 'slot-s88', gid: 40},
		{game: 'slot-ps', gid: 101},
		{game: 'slot-pg', gid: 102},
		{game: 'slot-mgp', gid: 114},
		{game: 'slot-mgp2', gid: 114},
		{game: 'slot-ka', gid: 118},
		{game: 'slot-lv2', gid: 119},
		{game: 'slot-vp', gid: 127},
		{game: 'slot-pm', gid: 210},
		{game: 'slot-hb', gid: 260},
		{game: 'slot-hb2', gid: 260},
		{game: 'slot-jk', gid: 106},
		{game: 'cq-slot', gid: 252},
		{game: 'slot-nt', gid: 288, isProd: true},
		{game: 'spadegaming', gid: 263}, // popup
		{game: 'slot-sg', gid: 263},
		{game: 'slot-nc', gid: 289, isProd: true},
		{game: 'slot-rt', gid: 290, isProd: true},
		{game: 'slot-jl', gid: 164, isProd: true},
		{game: 'slot-fs', gid: 294},
		{game: 'cf388', gid: 264},
		{game: 'slot-jb', gid: 278, isProd: true},
		{game: 'slot-fc', gid: 270, isProd: true},
		{game: 'slot-sp', gid: 271},
		{game: 'slot-ap', gid: 273, isProd: true},
		{game: 'slot-hs', gid: 275, isProd: true},
		{game: 'slot-bng', gid: 276, isProd: true},
		{game: 'slot-png', gid: 277, isProd: true},
		{game: 'slot-alz', gid: 281, isProd: true},
		{game: 'slot-ebtg', gid: 282, isProd: true},
		{game: 'slot-ep', gid: 283, isProd: true},
		{game: 'slot-ams', gid: 284},
		{game: 'slot-ibx', gid: 285, isProd: true},
		{game: 'slot-rlx', gid: 286},
		{game: 'slot-emp', gid: 293, isProd: true},
		{game: 'slot-ns', gid: 295},
		{game: 'slot-ss', gid: 296},
		// Live casino
		{game: 'ag-suit', gid: 13},
		{game: 'p-suit', gid: 15},
		{game: 'ab-suit', gid: 19},
		{game: 'gp-suit', gid: 21},
		{game: 's-suit', gid: 37},
		{game: 'pm-suit', gid: 210, gc: 101},
		{game: 'mg-suit', gid: 114, group: 'Live Dealer', list: true},
		{game: 'wm-suit', gid: 123},
		{game: 'ebet-suit', gid: 171, gc: 'LC'},
		{game: 'og-suit', gid: 177, gc: 'LC'},
		{game: 'vivo-suit', gid: 178, gc: 'LC'},
		{game: 'sexy-suit', gid: 265, gc: 'MX-LIVE-001'},
		{game: 'sa-suit', gid: 167, gc: 'LC'},
		{game: 'ion-suit', gid: 120, gc: 'BACCARAT'},
		{game: 'evo-suit', gid: 113},
		{game: 'evo-suit2', gid: 287, gc: 'LC'},
		// Others
		{game: 'balak4d', gid: 4},
		{game: 'luxe4d', gid: 5},
		{game: 'spribe', gid: 274, group: 'others', list: true},
		{game: 'p93', gid: 112, group: '', list: true},
		// Fish
		{game: 'vp-fish', gid: 127, group: 'fishing', list: true},
		{game: 'ka-fish', gid: 118, group: 'fish', list: true},
		{game: 'jk-fish', gid: 106, group: 'Fishing', list: true},
	];

	$(document).on('click', '.j-winopen', function() {
		let act = $(this).attr('action'),
			game = gameList.find(f => f.game === act),
			code = $(this).attr('gc') || (game ? (game.gc || '') : '');

		if (game && (game.isProd || location.host.includes('demolx2.com'))) {
			if (game.list) {
				window.open(`/secure/shr/playGameList.html?type=${act}&gid=${game.gid}&group=${game.group}`, "GW", "width=1280,height=720");
			} else {
				window.open(`/secure/shr/playGame.html?type=${act}&gid=${game.gid}&gc=${code}`, "GW", "width=1280,height=720");
			}
			return false;
		}

		var action = $(this).attr('action'),
			val = {
				url: 'launchGamesVS.html?r=',
				gamecode: '&a='+action,
				name: '',
				width: 1024,
				height: 768,
				resizable : true,
				location: false,
				menubar: false,
				scrollbars: false,
				status: false,
				toolbar: false
			},
			gc = '';

		if($(this).attr('gc')){
			gc = '&b='+$(this).attr('gc');
		}

		if(action == 'wsport'){
			val.name = 'W-Sport';
		}
		else if (action == 'isport') {
			val.name = 'I-Sport';
		}
		else if (action == 'ssport') {
			val.name = 'S-Sport';
		}
		else if (action == 'ssport2g') {
			val.name = 'S-Sport';
		}
		else if (action == 'ab-suit') {
			val.name = 'AB-Casino';
		}
		else if (action == 'p-suit') {
			val.name = 'PT-Casino';
			val.height = 800;
		}
		else if (action == 'gp-suit') {
			val.name = 'GP-Casino';
		}
		else if (action == 'ag-suit') {
			val.name = 'AG-Casino';
		}
		else if (action == 'mg-suit') {
			val.name = 'MG-Casino';
		}
		else if (action == 's-suit') {
			val.name = 'GP-Casino';
		}
		else if (action == 'evo-suit') {
			val.name = 'EVO-Casino';
		}
		else if (action == 'ion-suit') {
			val.name = 'ION-Casino';
		}
		else if (action == 'gp-slot') {
			val.name = 'GP-Egames';
			val.height = 800;
		}
		else if (action == 'pt-slot') {
			val.name = 'PT-Egames';
		}
		else if (action == 'mg-slot') {
			val.name = 'MG-Egames';
			val.height = 800;
		}
		else if (action == 'pm-slot') {
			val.name = 'Pragmatic-Egames';
			val.height = 800;
		}
		else if (action == 'pm-suit') {
			val.name = 'Pragmatic-Casino';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'gss-slot') {
			val.name = 'GSS-Egames';
			val.height = 800;
		}
		else if (action == 'ka-slot') {
			val.name = 'KA-Egames';
			val.height = 800;
		}
		else if (action == 'ka-fish') {
			val.name = 'KA Fish';
			val.height = 800;
		}
		else if (action == 'ka-others') {
			val.name = 'KA Others';
			val.height = 800;
		}
		else if (action == 'ttg') {
			val.name = 'Ttg';
		}
		else if (action == 'playstar') {
			val.name = 'PlayStar';
		}
		else if (action == 'pgsoft') {
			val.name = 'PGSoft';
		}
		else if (action == 'sbsport') {
			val.name = 'SB-Sport';
			val.width = 1285;
		}
		else if (action == 'idn') {
			val.name = 'IDN Poker';
			val.height = 800;
		}
		else if (action == 'idn2') {
			val.name = 'IDN Poker';
			val.height = 800;
		}
		else if (action == 'cockft') {
			val.name = 'CockFt';
		}
		else if (action == 'joker') {
			val.name = 'Joker';
		}
		else if (action == 'jk-slot') {
			val.name = 'Joker-Egames';
		}
		else if (action == 'jk-fish') {
			val.name = 'Joker Fish';
		}
		else if (action == 'flashtech') {
			val.name = 'CMD Sport';
		}
		else if (action == 'others-pt') {
			val.name = 'PT-Egames';
		}
		else if (action == 'tangkas') {
			val.name = 'Tangkas Game';
			val.width = 960;
			val.height = 600;
		}
		else if (action == 'fishace') {
			val.name = 'Fish Ace';
			val.width = 1300;
			val.height = 740;
		}
		else if (action == 'fish') {
			val.name = 'Ocean King 2';
			val.width = 1300;
			val.height = 740;
		}
		else if (action == 'fishOD') {
			val.name = 'Ocean Dragon';
			val.width = 1300;
			val.height = 740;
		}
		else if (action == 'minigame') {
			val.name = 'Mini Game';
			val.width = 960;
			val.height = 600;
		}
		else if (action == 'slotace') {
			val.name = 'Slot ACE';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'isin4d') {
			val.name = 'Isin4D';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'ion-isin4d') {
			val.name = 'Isin4D';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'a8texas') {
			val.name = 'Asia8 Texas';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'a8dominogaple') {
			val.name = 'Asia8 Domino Gaple';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'p2play') {
			val.name = 'P2PLAY';
			val.width = 1300;
			val.height = 740;
		}
		else if (action == 'worldmatch') {
			val.name = 'WORLDMATCH';
			val.width = 1300;
			val.height = 740;
		}
		else if (action == 'habanero') {
			val.name = 'Habanero';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'spadegaming') {
			val.name = 'Spade Gaming';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'sa-suit') {
			val.name = 'SA-Casino';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'sexy-suit') {
			val.name = 'Sexy Baccarat';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'og-suit') {
			val.name = 'Oriental Gaming';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'dg-suit') {
			val.name = 'Dream Gaming';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'ebet-suit') {
			val.name = 'Ebet';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'gn-slot') {
			val.name = 'Genesis';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'nt-slot') {
			val.name = 'Netent';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'cq-slot') {
			val.name = 'CQ9';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'balakplay') {
			val.name = 'BalakPlay';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'cf388') {
			val.name = 'CockFT SV388';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'vivo-suit') {
			val.name = 'Vivo Gaming';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'wm-suit') {
			val.name = 'WM Casino';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 's88-slot') {
			val.name = 'Slot88';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'wbsport') {
			val.name = 'Wbet-Sport';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'p93') {
			val.name = '93Connect';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'capit') {
			val.name = 'Capit';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'gioco') {
			val.name = 'Gioco Plus';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'vpower') {
			val.name = 'V-Power';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'vp-slot') {
			val.name = 'Vpower-Egames';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'vp-fish') {
			val.name = 'Vpower Fish';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'tsg-slot') {
			val.name = 'TSG';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == '1gaming') {
			val.name = '1 Gaming';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'balak4d') {
			val.name = 'Balak4D';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'live22-slot') {
			val.name = 'Live22';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-lv2') {
			val.name = 'Live22';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-vp') {
			val.name = 'Vpower';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-s88') {
			val.name = 'Slot88';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-pm') {
			val.name = 'Pragmatic-Egames';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-pg') {
			val.name = 'PGSoft';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-jk') {
			val.name = 'Joker-Egames';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-hb') {
			val.name = 'Habanero';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-pt') {
			val.name = 'Playtech-Egames';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-ka') {
			val.name = 'KA-Egames';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-ps') {
			val.name = 'PlayStar';
			val.width = 1280;
			val.height = 720;
		}
		else if (action == 'slot-mgp') {
			val.name = 'MG-Egames';
			val.width = 1280;
			val.height = 720;
		}


		winOpen('/secure/shr/'+val.url+Math.random()+val.gamecode+gc, val.name, val.width, val.height, val.resizable, val.location, val.menubar, val.scrollbars, val.status, val.status);

		return false;

	});

});

function winOpen(URL, windowName, width, height, resizable, location, menubar, scrollbars, status, toolbar){
	var windowFeatures;
	windowFeatures = '';
	if (width != '' && width != null){
		windowFeatures = windowFeatures+'width='+width+',';
	}
	if (height != '' && height != null){
		windowFeatures = windowFeatures+'height='+height+',';
	}
	if (resizable){
		windowFeatures = windowFeatures+'resizable,';
	}
	if (location){
		windowFeatures = windowFeatures+'location,';
	}
	if (menubar){
		windowFeatures = windowFeatures+'menubar,';
	}
	if (scrollbars){
		windowFeatures = windowFeatures+'scrollbars,';
	}
	if (status){
		windowFeatures = windowFeatures+'status,';
	}
	if (toolbar){
		windowFeatures = windowFeatures+'toolbar,';
	}
	window.open(URL, windowName, windowFeatures);
}

/*function openGameMg(gameCode){
	winOpen('mgegamesPop.html?r='+Math.random()+'&gameCode='+gameCode, 'MG-Egames', 1024, 768, true, false, false, false, false, false);
}

function openGamePt(gameCode){
	winOpen('playtechegamesPop.html?r='+Math.random()+'&gameCode='+gameCode, 'PT-Egames', 1024, 800, true, false, false, false, false, false);
}

function openGameGp(gameCode){
	winOpen('gameplayegamesPop.html?r='+Math.random()+'&gameCode='+gameCode, 'GP-Egames', 1024, 800, true, false, false, false, false, false);
}*/
