if(typeof NICK == "undefined" || !NICK) var NICK = {};
NICK.namespace("games.player");

// sc
NICK.games.player.gamesInitId = -1;
NICK.games.player.gamesLaunchId = -1;
NICK.games.player.gameDivName = "games-player-game";
NICK.games.player.gameSwfObjectId = "gameSwf";
NICK.games.player.intervalLaunchGame = 6000;
NICK.games.player.intervalPageReady = 500;

NICK.games.player.adSwfObjectId = "GamePlayer";

if(window.self.location == window.top.location) {
	$(document).ready(function() {
		NICK.imx.callIMXPlay(NICK.get("cmsId"), NICK.get("type") );
		NICK.games.player.checkCookie();
	});
} else {
	NICK.imx.callIMXPlay(NICK.get("cmsId"), NICK.get("type") );
	NICK.games.player.checkCookie();
}
/* document.ready not firing when the games page is framed:
	http://www.nickjr-d.mtvi.com/test/icarlystacknstash.html
	http://www.addictinggames.com/gameoftheweekoftheyear.html
*/

NICK.games.player.launchGame = function() {
	if(NICK.games.player.gamesLaunchId >= 0) {
		clearTimeout(NICK.games.player.gamesLaunchId);
	}

	doLaunchSwf(NICK.games.player.gameSwfObjectId);
	

	/*
	var obj = document.getElementById("120AdDiv");
	if(obj){
		obj.style.display="";
		delete obj;
	}
	*/
}

NICK.games.player.staticAd = function(){
	NICK.games.player.gamesLaunchId = setTimeout("NICK.games.player.launchGame()", NICK.games.player.intervalLaunchGame);
}

NICK.games.player.videoAd = function() {
	if(NICK.games.player.gamesLaunchId >= 0) {
		clearTimeout(NICK.games.player.adLaunchId);
	}

	doLaunchSwf(NICK.games.player.adSwfObjectId);
	

	/*
	var obj = document.getElementById("120AdDiv");
	if(obj){
		obj.style.display="";
		delete obj;
	}
	*/
}

NICK.games.player.checkCookie = function() {
	NICK.games.player.adFrequency = KIDS.ads.getVideoAdFrequency();
	var tmpCookVal = KIDS.utils.getCookie("NICK.games.player.plycnt");
	
	if(!tmpCookVal || tmpCookVal >= NICK.games.player.adFrequency){
		NICK.games.player.cookieVal = 0;
	}else{
		NICK.games.player.cookieVal = parseInt(tmpCookVal) + 1;
	}
	
	NICK.utils.doLog("adType: " + NICK.games.player.adType);
	NICK.utils.doLog("cookie: " + NICK.games.player.cookieVal);
	
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+1);	
	document.cookie="NICK.games.player.plycnt=" +NICK.games.player.cookieVal+ ";expires="+exdate.toGMTString();

	if(NICK.games.player.cookieVal == 0){
		if(NICK.games.player.adType == 'video'){
			NICK.games.player.adLaunchId = setTimeout("NICK.games.player.videoAd()", NICK.games.player.intervalPageReady);
		}else{
			NICK.games.player.adLaunchId = setTimeout("NICK.games.player.staticAd()", NICK.games.player.intervalPageReady);
		}
	}else{
		NICK.games.player.gamesLaunchId = setTimeout("NICK.games.player.launchGame()", NICK.games.player.intervalPageReady);
	}

}

var launchGame = NICK.games.player.launchGame;

// support the game's team ad preloader
function AdLoaderMessages(str) {
	NICK.utils.doLog("Ad Preloader: "+str);
}
