// sc
var gamesInitId = -1;
var gamesLaunchId = -1;
var gameDivName = "gameplayer_content";
var gameSwfObjectId = "gameplayer";
var intervalLaunchGame = 7000;
var intervalPageReady = 500;

var adSwfObjectId = "PreLoader";
var videoAdFrequency = 0;

window.addEvent("domready", function() {  
	checkCookie();
});

var NICK = {};
NICK["games"]={};
NICK.games.launchGame = function() {
	SBCOM.utils.doLog("Nick.games.launchGame");
}
//support the game's team ad preloader
function AdLoaderMessages(str) { 
SBCOM.utils.doLog("Ad Preloader: "+str);
}
function checkCookie() {
	var tmpCookVal = SBCOM.utils.getCookie("SB.games.player.plycnt");
	
	if(!tmpCookVal || tmpCookVal >= videoAdFrequency){
		cookieVal = 0;
	}else{
		cookieVal = parseInt(tmpCookVal) + 1;
	}
	if(typeof adType != "undefined"){
		SBCOM.utils.doLog("adType: " + adType);
		SBCOM.utils.doLog("cookie: " + cookieVal);
		
		var exdate = new Date();
		exdate.setDate(exdate.getDate()+1);	
		document.cookie="SB.games.player.plycnt=" + cookieVal + ";expires="+exdate.toGMTString();
		if(cookieVal == 0){
			if(adType == 'video'){
				adLaunchId = setTimeout("videoAd()", intervalPageReady);
			}else{
				adLaunchId = setTimeout("staticAd()", intervalPageReady);
			}
		}else{
			gamesLaunchId = setTimeout("launchGame()", intervalPageReady);
		}
	}else launchGame();
}

function staticAd(){
	gamesLaunchId = setTimeout("launchGame()", intervalLaunchGame);
}

function videoAd() {
	if(gamesLaunchId >= 0) {
		clearTimeout(NICK.games.player.adLaunchId);
	}
	doLaunchSwf(adSwfObjectId);	
}
/*
function doInitGamesPage() {
	// Make sure the div is ready on the page. IE Fix - document.ready()
	if(!$(gameDivName)) {
		if(gamesInitId >= 0) return;
		gamesInitId = setTimeout("doInitGamesPage()", intervalPageReady);
		return;
	} else if(gamesInitId >= 0) {
		clearTimeout(gamesInitId);
	}

	// ad timeout
	gamesLaunchId = setTimeout("launchGame()", intervalLaunchGame);
}
*/
function launchGame() {
	if(gamesLaunchId >= 0) {
		clearTimeout(gamesLaunchId);
	}

	/*
	var gameSwfObject = swfObjHash == null ? null : swfObjHash[gameSwfObjectId];
	if(gameSwfObject != null) gameSwfObject.write(gameDivName);
	*/
	gameplayer.write("gameplayer_content");
	
	/*var obj = document.getElementById("120AdDiv");
	if(obj){
		obj.style.display="";
		delete obj;
	}*/
}
function doLaunchSwf(swfId){
	
	SBCOMadSwf.write(swfId);
}
/*

intervalLaunchGame = 4000;

window.addEvent("domready", function() {  
	doInitGamesPage();
});
*/
/* 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
*/
