var myWindow;

jQuery(document).ready(function($) {
	/* Load the Main flash movie */
	var swf = "flash/index.swf?" + Math.floor(Math.random()*11);
	var flashvars = {};
	var params = {};
		params.allowscriptaccess = "always";
		params.wmode = "transparent";
		params.menu = "false";
		params.bgcolor = "#000000";
		params.scale = "noscale";
	var attributes = {};
	swfobject.embedSWF(swf, "FlashBox", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

	/* Fit it to screen */
	swffit.fit('FlashBox', '100%', '100%', '100%', '100%', true, true);
	
	/* Auto-Trigger Popup */
	var hash = window.location.hash;
	hash = hash.substring(1);
	if(hash){
		do_popup(hash);
	}

});

/**
 * do_popup
 * Called by actionscript. Triggers the named popup.
 */
function do_popup(popupName){
	var width, height, targetUrl;

	switch(popupName){
		case "Game Room Raider":
			targetUrl = "game_popup/?game=roomraider"
			width = 840;
			height = 641;
		break;
		
		case "Game Shoot The Fruit":
			targetUrl = "game_popup/?game=shootthefruit"
			width = 840;
			height = 641;
		break;
		
		case "Game Snack Grab":
			targetUrl = "game_popup/?game=snackandgrab"
			width = 840;
			height = 641;
		break;
		
		case "Moms":
			targetUrl = "moms/";
			width = 500;
			height = 800;
		break;
		
		case "WhatsNew":
			targetUrl = "whats_new/";
			width = 500;
			height = 800;
		break;
		
		case "Share":
			targetUrl = "share/";
			width = 500;
			height = 800;
		break;
		
		case "Join Club":
		
		break;
		
		case "Terms":
			targetUrl = "terms/"
			width = 840;
			height = 641;
		break;
		
		case "Privacy":
			targetUrl = "privacy/"
			width = 840;
			height = 641;
		break;
		
		case "Win":
			targetUrl = "win/";
			width = 500;
			height =  800;
		break;
		
		case "Contact":
			targetUrl = "contact/";
			width = 500;
			height =  800;
		break;
		
		default:
		
	}

	/* Change Width if viewing on a small screen */
	if(screen.height <= 700){
		if(height > 600){
			height = 400;
		}
	}

	if(targetUrl){
		if(myWindow){
			myWindow.close();
		}
		// Calculate position
		var top = (screen.height / 2) - (height / 2);
		var left = (screen.width / 2) - (width / 2);
		
		myWindow = window.open(targetUrl, "fsPopup", "status=0,height="+height+",width="+width+",resizable=no,top=" + top + ",left=" + left + ",scrollbars=yes");
	}
}
