// Quick browser detection
var isMoz = (document.getElementById && !document.all);
var isIE = (document.getElementById && document.all);
var isNav = (document.layers && !document.getElementById);

// window.status message system
function showStatus(msg) { window.status = msg; return true; }

// onmouseover rollovers
function on(imgName) {
	if (document.images) {
		eval("var " + imgName + "_on" + "= new Image()");
		eval(imgName.toString() + "_on.src = \"img\/" + imgName + "-on.gif\"");
		document[imgName].src = eval(imgName + "_on.src");
	}
}

// onmouseout rollovers
function off(imgName) {
	if (document.images) {
		eval("var " + imgName + "_off" + "= new Image()");
		eval(imgName.toString() + "_off.src = \"img\/" + imgName + "-off.gif\"");
		document[imgName].src = eval(imgName + "_off.src");

		return showStatus('');
	}
}







// Inline Secure Flash placement function
function secureflash(file,id,width,height,quality,bgcolor,wmode) {

	var mode;
	if (wmode) { mode = "transparent"; } else { mode = "opaque"; }

	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"" + id + "\"><param name=\"movie\" value=\"" + file + "\" \/><param name=\"quality\" value=\"" + quality + "\" \/><param name=\"bgcolor\" value=\"" + bgcolor + "\" \/><param name=\"wmode\" value=\"" + mode + "\" \/><param name=\"menu\" value=\"false\" \/><embed src=\"" + file + "\" quality=\"" + quality + "\" bgcolor=\"" + bgcolor + "\" width=\"" + width + "\" height=\"" + height + "\" menu=\"false\" name=\"" + id + "\" type=\"application\/x-shockwave-flash\" pluginspage=\"https:\/\/www.macromedia.com\/go\/getflashplayer\"><\/embed><\/object>");

}

// Inline Flash placement function
function flash(file,id,width,height,quality,bgcolor,wmode) {

	var mode;
	if (wmode) mode = "transparent";
	else mode = "opaque";

	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"" + id + "\"><param name=\"movie\" value=\"" + file + "\" \/><param name=\"quality\" value=\"" + quality + "\" \/><param name=\"bgcolor\" value=\"" + bgcolor + "\" \/><param name=\"wmode\" value=\"" + mode + "\" \/><param name=\"menu\" value=\"false\" \/><embed src=\"" + file + "\" quality=\"" + quality + "\" bgcolor=\"" + bgcolor + "\" width=\"" + width + "\" height=\"" + height + "\" menu=\"false\" name=\"" + id + "\" type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\"><\/embed><\/object>");

}

function flashSwap(file,id,width,height,quality,bgcolor,wmode,div) {

	var mode;
	if (wmode) mode = "transparent";
	else mode = "opaque";

	var temp = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"" + id + "\"><param name=\"movie\" value=\"" + file + "\" \/><param name=\"quality\" value=\"" + quality + "\" \/><param name=\"bgcolor\" value=\"" + bgcolor + "\" \/><param name=\"wmode\" value=\"" + mode + "\" \/><param name=\"menu\" value=\"false\" \/><embed src=\"" + file + "\" quality=\"" + quality + "\" bgcolor=\"" + bgcolor + "\" width=\"" + width + "\" height=\"" + height + "\" menu=\"false\" name=\"" + id + "\" type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\"><\/embed><\/object>";
	eval("document.getElementById('" + div + "').innerHTML = temp");

}

function flashLogout() {

	document.location = "http://" + location.host + "/members/logout.asp";
	//document.reload(true);
}

var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000);

function flashLogin() {
	//document.cookie = "TARGET=" + escape(document.location)+"; path=/; expires" + expiry.toGMTString();
	document.cookie = "TARGET=" + escape(document.location)+"; path=/; domain=ytv.com; expires" + expiry.toGMTString();

}

function flashLoginButton() {
	document.cookie = "TARGET=" + escape(document.location)+"; path=/; domain=ytv.com; expires" + expiry.toGMTString();

	var is_mac, is_ie

	var agt=navigator.userAgent.toLowerCase();
	var is_mac=(agt.indexOf("mac")!=-1);
	var is_op=(agt.indexOf("opera") !=-1);
	var is_ie=(is_op==false && agt.indexOf("msie") !=-1);

	//if ((is_mac) && (is_ie)) {

	//	if (document.location != "http://" + location.host + "/members/login.asp") {
	//		document.location = "http://" + location.host + "/members/login.asp";
	//	}
	//}

}

function setTargetCookies() {
	document.cookie = "TARGET=" + escape(document.location)+"; path=/; domain=ytv.com expires" + expiry.toGMTString();
}

function setTimeZone(timezone) {
	var today = new Date();
	var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000);
	document.cookie = "YTVguide=TimeZone="+escape(timezone)+"; path=/; expires="+expiry.toGMTString();
	document.location = document.location;
}


function openWindow(url, width, height, options, name) {
	var newWin = window.open(url, name, "width=" + width + ",height=" + height + "," + options);
}



var winSite;

// leaving Ytv.com alert box
function linkOutside(strURL) {
	//if (confirm('You are now leaving the YTV site!\n\nTo return to YTV.com simply close the new window.')) {
	winSite = window.open(strURL, "pop_up_ad");
	var winMsg = window.open("/gamepad/common/ads/message/leavingYTV.asp", "Leaving_YTV", "noresize,scrollbars=no,width=350,height=432,status=no");
	//}
}

/////////////////////////////////////////
//	SITEKICK ROUTINES :: START
function launchSKActivate() { win = window.open("/common/inc/sitekick/checkSKStatus.asp", "win", "height=400,width=550,scrollbars=no,location=no,menu=no,resize=no"); }
function launchSKKickstart() { win = window.open("/sitekick/kickstart.asp", "win", "height=400,width=550,scrollbars=no,location=no,menu=no,resize=no"); }
function launchSKDeactivate() { win = window.open("/common/inc/sitekick/deactivateSitekick.asp", "win", "height=400,width=550,scrollbars=no,location=no,menu=no,resize=no"); }
//	SITEKICK ROUTINES :: END
/////////////////////////////////////////


function openVideo(id) { link = window.open("video.asp?videoID=" + id,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,width=320,height=240,left=250,top=250"); }
function openPic(url, w, h) { link = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,width="+w+",height="+h+",left=250,top=250"); }


/////////////////////////////////////////
//	OLD ROUTINES -- DO NOT USE! :: START
function preloadCustomSize(strTheme,numID,numWidth,numHeight) {
	if (strTheme == undefined || strTheme == "") strTheme = "green";
	if (numID == undefined || numID == -1) alert("ERROR! GameID is undefined!");
	else w = window.open("/gamepad/play/games/preloader/index.asp?theme=" + strTheme + "&id=" + numID + "&w=" + numWidth + "&h=" + numHeight,"game","width=" + numWidth +",height=" + numHeight + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
}

function launchOttawa() { win = window.open("/ottawaTimeChange.asp", "win", "height=300,width=400,scrollbars=no,location=no,menu=no,resize=no"); }
function reloadPageWithQueryString(strURL,strQueryString) { document.location = strURL + "?" + strQueryString; };
function launchGame(game) { link = window.open(game,"","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); }
function launchGameFromAnywhere(folder,gameID) { link = window.open("/games/game.asp?gameFolder=/games/" + folder + "/&swf=game.swf&gameID=" + gameID,"","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); }
function launchGameFromAnywhereNoPreloader(folder,gameID) { link = window.open("/games/" + folder + "/game.asp?gameID=" + gameID,"","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); }
function launchPromoFromAnywhereNoPreloader(folder,gameID,promoURL) { link = window.open("/games/" + folder + "/game.asp?gameID=" + gameID,"","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); document.location = promoURL; }
function launchCustomGameWindow(gameURL,winWidth,winHeight) { if (!winWidth) { winWidth = 550; } if (!winHeight) { winHeight = 400; } var game = window.open(gameURL,'game',"width=" + winWidth + ",height=" + winHeight + ",scrollbars=no,location=no,menu=no,resize=no"); }
function launchCustomGameWindowWithPromo(promoURL,gameURL,winWidth,winHeight) { if (!winWidth) { winWidth = 550; } if (!winHeight) { winHeight = 400; } var game = window.open(gameURL,'game',"width=" + winWidth + ",height=" + winHeight + ",scrollbars=no,location=no,menu=no,resize=no"); document.location = promoURL; }
function launchSpiderman() { win = window.open("/programming/shows/spiderman/minisite/index.html", "win", "height=560,width=800,scrollbars=no,location=no,menu=no,resize=no"); }
//	OLD ROUTINES -- DO NOT USE! :: END
/////////////////////////////////////////


/////////////////////////////////////////
//	GAME & PRELOADER ROUTINES :: START
function preload(sTheme,nID,nWidth,nHeight) {
	if (nWidth == undefined || nWidth == "") nWidth = 550;
	if (nHeight == undefined || nHeight == "") nHeight = 400;
	if (sTheme == undefined || sTheme == "") sTheme = "green";

	if (nID == undefined || nID == -1) alert("ERROR! GameID is undefined!");
	else w = window.open("/gamepad/play/games/preloader/index.asp?theme=" + sTheme + "&id=" + nID + "&w=" + nWidth + "&h=" + nHeight,"game","width=" + nWidth + ",height=" + nHeight + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
}






//	Games.Preload.js: Preload functions for games
function Preload(sTheme,nID,nWidth,nHeight,sURL) {
	//	Gamepad server test
	var s = (window.location.toString().indexOf("gamepad.ytv.com") != -1) ? "http://www.ytv.com" : "";

	//	The functions
	var a = arguments;
	alert (a);
	switch (a.length) {
		case 0: PreloadError(); break;
		case 1:
			if (typeof a[0] == "number") w = window.open(s + "/gamepad/play/games/preloader/index.asp?theme=green&gameid=" + a[0] + "&w=550&h=400","game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
			else PreloadError();
			break;
		case 2:
			if (typeof a[0] == "string" && typeof a[1] == "number") w = window.open(s + "/gamepad/play/games/preloader/index.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400","game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
			else PreloadError();
			break;
		case 3:
			if (typeof a[0] == "string" && typeof a[1] == "number" && typeof a[2] == "string") {
				if (a[2].indexOf("|") == 0) {
					w = window.open(s + "/gamepad/play/games/preloader/index.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400&flashvars=" + a[2],"game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
				} else { w = window.open(s + "/gamepad/play/games/preloader/index.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400","game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); window.location = a[2]; }
			}
			else PreloadError();
			break;
		case 4:
			if (typeof a[0] == "string" && typeof a[1] == "number" && typeof a[2] == "number" && typeof a[3] == "number") w = window.open(s + "/gamepad/play/games/preloader/index.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=" + a[2] + "&h=" + a[3],"game","width=" + a[2] + ",height=" + a[3] + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
			else PreloadError();
			break;
		case 5:
			if (typeof a[0] == "string" && typeof a[1] == "number" && typeof a[2] == "number" && typeof a[3] == "number" && typeof a[4] == "string") { w = window.open(s + "/gamepad/play/games/preloader/index.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400","game","width=" + a[2] + ",height=" + a[3] + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); window.location = a[4]; }
			else PreloadError();
			break;
	}
}


///////////////////////////////////////////////////////////////
//	Interstitial preloader - show film before game loads.
function Adload(sTheme,nID,nWidth,nHeight,sURL) {

	//Gamepad server test.
	var s = (window.location.toString().indexOf("gamepad.ytv.com") != -1) ? "http://www.ytv.com" : "";

	
	//	Action determined by number and type of arguments.
	var a = arguments;
	switch (a.length) {
		case 0: PreloadError(); break;
		case 1:
			if (typeof a[0] == "number") w = window.open(s + "/interstitial.asp?theme=green&gameid=" + a[0] + "&w=550&h=400","game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
			else PreloadError();
			break;
		case 2:
			if (typeof a[0] == "string" && typeof a[1] == "number") w = window.open(s + "/interstitial.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400","game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
			else PreloadError();
			break;
		case 3:
			if (typeof a[0] == "string" && typeof a[1] == "number" && typeof a[2] == "string") {
				if (a[2].indexOf("|") == 0) {
					w = window.open(s + "/interstitial.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400&flashvars=" + a[2],"game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
				} else { w = window.open(s + "/interstitial.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400","game","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); window.location = a[2]; }
			}
			else PreloadError();
			break;
		case 4:
			if (typeof a[0] == "string" && typeof a[1] == "number" && typeof a[2] == "number" && typeof a[3] == "number") w = window.open(s + "/interstitial.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400","game","width=" + a[2] + ",height=" + a[3] + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
			else PreloadError();
			break;
		case 5:
			if (typeof a[0] == "string" && typeof a[1] == "number" && typeof a[2] == "number" && typeof a[3] == "number" && typeof a[4] == "string") { w = window.open(s + "/interstitial.asp?theme=" + a[0] + "&gameid=" + a[1] + "&w=550&h=400","game","width=" + a[2] + ",height=" + a[3] + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); window.location = a[4]; }
			else PreloadError();
			break;
	}
}




function PreloadError() { alert("Error: Incorrect number of arguments!\nUsage: Preload(ThemeColour,GameID,[Width],[Height],[RedirectURL])"); }

function AdditionalParameters(sVars) { return sVars.slice(1,sVars.length - 1); }

//	FLASH DEBUG CONSOLE POPUP
function openDebug() {
	var l = String(document.location);
	if (l.indexOf("debug") != -1 || l.indexOf("dev") != -1) var d = window.open("/test/debug/debug.html","debug","width=550,height=400,scrollbars=no,menubar=no,toolbar=no,location=no,status=no,resizable=yes");
}
//function focusDiv(sDivID) { var e = document.getElementByID(sDivID); }
//	GAME & PRELOADER ROUTINES :: END
/////////////////////////////////////////

 
 