// sc
var gamesInitId = -1;
var gamesLaunchId = -1;
var gameDivName = "nickgameswf_content";
var gameSwfObjectId = "nickgameswf";
var intervalLaunchGame = 7000;
var intervalPageReady = 500;

function doInitGamesPage() {
	// Make sure the div is ready on the page. IE Fix - document.ready()
	if(!$('#'+gameDivName) || $('#'+gameDivName).width() <= 0) {
		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);
	*/
	if(swfObjHash && swfObjHash[gameSwfObjectId]) swfObjHash[gameSwfObjectId].launchSwf();
	
	var obj = document.getElementById("120AdDiv");
	if(obj){
		obj.style.display="";
		delete obj;
	}
}

if(window.self.location == window.top.location) {
	intervalLaunchGame = 4000;
	$(document).ready(doInitGamesPage);
} else {
	intervalLaunchGame = 6000;
	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
*/
