// Ask if want to play full screen or in pop-up window
function playGame(gameName) {
	if (screen.width && navigator.userAgent.indexOf("Opera") == -1) {
		// MSIE people get VBScript Yes/No message box
		if (navigator.appName.indexOf("Microsoft") != -1) vb_confirm(gameName);
		else {
			// Others get OK/Cancel message box
			fullscreen = confirm("Would you like to play full-screen?\n(OK for full-screen, Cancel for pop-up window.)");
			popUpGame(gameName, fullscreen);
		}
	}
	else popUpGame(gameName, false);
}

// Open game in popup window
function popUpGame(gameName, fullscreen) {
	// Different window sizes for each game
	switch (gameName) {
		case "asteroids": w = 500; h = 375; break;
		case "invaders": w = 500; h = 410; break;
		case "pacman": w = 360; h = 420; break;
		case "tictactoe": w = 320; h = 420; break;
		case "hexxagon": w = 532; h = 420; break;
		case "tetris": w = 382; h = 380; break;
		case "snake": w = 360; h = 300; break;
		case "simon": w = 500; h = 400;
	}

	// Full screen sir?
	if (fullscreen) {
		w = screen.width - 6;
		h = screen.height - 56;
		posText = ",top=0,left=0,fullscreen";
		alert("You can press the 'Q' key to quit at any time.");
	}
	else if (screen.width) {
		x = (screen.width - w) / 2 - 15;
		y = (screen.height - h) / 2 - 20;
		posText = ",top=" + y + ",left=" + x;
	}
	else posText = "";

	// Have fun

	switch (gameName) {
		case "asteroids": gameFile = "games/asteroids/neave_asteroids.swf"; break;
		case "invaders": gameFile = "games/invaders/neave_invaders.swf"; break;
		case "pacman": gameFile = "games/pacman/neave_pacman.swf"; break;
		case "tictactoe": gameFile = "games/tictactoe/neave_tictactoe.swf"; break;
		case "hexxagon": gameFile = "games/hexxagon/neave_hexxagon.swf"; break;
		case "tetris": gameFile = "games/tetris/neave_tetris.swf"; break;
		case "snake": gameFile = "games/snake/neave_snake.swf"; break;
		case "simon": gameFile = "games/simon/neave_simon.swf";
	}

	window.open(gameFile, gameName, "resizable,width=" + w + ",height=" + h + posText);
}

// Games page Flash-to-JavaScript for status bar links
function logo_DoFSCommand(cmd, args) {
	if (cmd == "statusOn") {
		var parent = neaveURL.substr(0, neaveURL.lastIndexOf("/"));
		window.status = parent.substr(0, parent.lastIndexOf("/") + 1);
	}
	if (cmd == "statusOff") window.status = "";
}

wlh = unescape(window.location.href);
pos = wlh.indexOf("index.");
neaveURL = (pos == -1) ? wlh : wlh.substr(0, pos);

if (navigator.appName.indexOf("Microsoft") != -1) {
	document.write('<script type="text/vbscript">\n' +
	'Sub vb_confirm(ByVal gameName)\n' +
	'fullscreen = MsgBox("Would you like to play full-screen?", 292, "Neave Games") - 7\n' +
	'Call popUpGame(gameName, fullscreen)\n' +
	'End Sub\n' +
	'Sub logo_FSCommand(ByVal cmd, ByVal args)\n' +
	'Call logo_DoFSCommand(cmd, args)\n' +
	'End Sub\n' +
	'</script>\n');
}
