Overlay = {};
(function(app) {
	app.gameId = "";
	app.elementId = "";
	
	app.init = function(elementId) {
		
		this.elementId = elementId;
		
		Shadowbox.init({
			onOpen: openHandler,
			onClose: closeHandler
		});
	}
	
	app.open = function(url, width, height, userId, gameId) {
		Shadowbox.open({
			content: url,
			player: "iframe",
				width: width,
			height: height
		});
	}
	
	app.flashElement = function() {
		return navigator.appName.indexOf("Microsoft") != -1 ? window[app.elementId] : document.getElementById(app.elementId);
	}
	
	var openHandler = function() {
		app.flashElement().openHandler();
	}
	
	var closeHandler = function() {
		if(Overlay.gameId != "") {
			GamePage.trackEvent("Games", "Close", Overlay.gameId);
			Overlay.gameId	= "";
		}
		app.flashElement().closeHandler()
	}
	
})(Overlay);

GamePage = {};
(function(app) {
	app.init = function(swf, width, height, flashVersion, userId, gameId) {
		
		if(!flashVersion)
			flashVersion = 8;
		
		$(document).ready(function(){
        
            $("#icons").hide();
            
			$("#container").css("margin-top",(($(document).height() - $("#container").height()) / 2) + "px");
			$("#container").css("width", (width - 10) + "px !important");
			$("#container").css("height", (height - 10) + "px !important");
			$("#instructions a").click(function(){
				$("#instructions").fadeOut("slow");
                		$("#icons").fadeIn("slow");
                		GamePage.trackEvent("Games", "Play", gameId);
				swfobject.embedSWF(swf, "flashContent", width, height, flashVersion + ".0.0", "", {userID: userId, gameID: gameId}, { allowscriptaccess: "sameDomain", menu: "false", wmode: "opaque", bgcolor: "#000000" }, { id: 555} );
			});
		});
	}
	
	app.trackEvent = function(category, action, label) {
		var _gaq = _gaq || [];
		_gaq.push(['_trackEvent', category, action, label]);
	}
})(GamePage);

NavigationUtil = {};
(function(app) {
	
	app.getCurrentURL = function() {
		return window.location.href;
	}
	
})(NavigationUtil);	

