//if (top != self && top.location.href.search(/stagexnet/i) == -1 && top.location.href.indexOf("https://partners.nvidia.com") == -1)
//	top.location = location;

var urlSansHTTP =  location.href.split("http://")[1];
var whichDomain = urlSansHTTP.substr(0, urlSansHTTP.indexOf("/"));
var relativePath = urlSansHTTP.substr(urlSansHTTP.indexOf("/"));

if (typeof(whichSite) != "undefined" && whichSite == "us" && (whichDomain == "nvidia.com" || whichDomain == "www.nvidia.com") && location.href.search(/nzone_section_gaming/i) == -1)
	location.href = "http://www.nzone.com" + relativePath;

var numWindows = 1;

var windows = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer == 4);
var NS6 = (navigator.vendor == "Netscape6");
var NS7 = (navigator.userAgent.indexOf("Netscape/7") > -1) ? true : false;
var IE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var IE6 = (navigator.userAgent.indexOf("MSIE 6") > -1) ? true : false;
var Mozilla = (navigator.userAgent.indexOf("Mozilla/5") > -1 && navigator.userAgent.indexOf("Netscape") == -1) ? true : false;
var Opera = (window.opera);

if (NS4) {
	layerRef = "document.layers";
	styleSwitch = "";
} else if (IE4) {
	layerRef = "document.all";
	styleSwitch = ".style";
} else { // if (NS6 || NS7 || Opera || Mozilla) {
	layerRef = "document.getElementById";
	styleSwitch = ".style";
}

// *************************
// FLASH DETECTION - START
// *************************
var flash4 = false;
var flash5 = false;
var flash6 = false;
var flash7 = false;
var flash8 = false;
var flash9 = false;
var maxVersion = 9;             // highest version we actually detect
var flashVersion = 0;          // version the user has

// write vbscript detection on ie win, since it doesn't support plugins array detection
if (IE && windows)
	document.write(
		'<scr' + 'ipt language=VBScript\> \n'
		+ 'on error resume next \n'
		+ 'flash4 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n'
		+ 'flash5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n'
		+ 'flash6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n'
		+ 'flash7 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n'
		+ 'flash8 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n'
		+ 'flash9 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n'
		+ '<\/scr' + 'ipt\> \n'
	);

if (navigator.plugins)
	if (navigator.plugins["Shockwave Flash"]) {      
		var version = parseInt(navigator.plugins["Shockwave Flash"].description.substring(16));
		flash4 = (version == 4);
		flash5 = (version == 5);
		flash6 = (version == 6);
		flash7 = (version >= 7);
	}

for (var i = 4; i <= maxVersion; i++)
	if (eval("flash" + i) == true)
		flashVersion = i;
// *************************
// FLASH DETECTION - END
// *************************

function change(name, i) {
	imageObj = eval(name + i);
	if (document.images && imageObj.complete)
		document[name].src = imageObj.src;
	return true;
}

function launchPic(path, imageNamePrefix, currentPicIndex, lastPicIndex, whichSite) {
	var strNext;
	var strPrevious;
	var strCaption = (typeof(captions) != "undefined" && typeof(captions[currentPicIndex]) != "undefined") ? captions[currentPicIndex] : "";

	switch (whichSite) {
		case "de":
			strNext = "Weiter";
			strPrevious = "Zur&uuml;ck";
			break;
		case "es":
			strNext = "Siguiente";
			strPrevious = "Anterior";
			break;
		case "fr":
			strNext = "Suivante";
			strPrevious = "Pr&eacute;c&eacute;dente";
			break;
		case "it":
			strNext = "Avanti";
			strPrevious = "Indietro";
			break;
		case "uk":
			strNext = "Next";
			strPrevious = "Previous";
			break;
		case "us":
			strNext = "Next";
			strPrevious = "Previous";
			break;
	}
	var tempStr = "<html><head><title>nZone</title><style type=\"text/css\">@import url( /docs/TEMPLATE/112/nzone_global.css ); BODY {background: #000000;} A { text-decoration: none;}</style><script language=\"JavaScript\" src=\"/docs/TEMPLATE/112/nzone_global.js\"></script><script language=\"JavaScript\">var path = \"" + path + "\"; var imageNamePrefix = \"" + imageNamePrefix + "\"; var currentPicIndex = " + currentPicIndex + "; var lastPicIndex = " + lastPicIndex + ";</script></head><body style=\"margin: 0px; background-color: #000000;\"><table border=\"0\" width=\"100%\" height=\"100%\"><tr valign=\"center\" align=\"center\"><td><img name=\"bigPic\" src=\"" + path + imageNamePrefix + currentPicIndex + ".jpg\"><div align=\"center\" class=\"gameNormal\" style=\"margin-top: 4px;\"><div id=\"caption\" style=\"height: 12px; margin-bottom: 2px;\">" + strCaption + "</div><span id=\"previousLink\"><a href=\"javascript:switchPic(0, '" + whichSite + "');\">&lt;&lt; " + strPrevious + "</a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id=\"status\">" + currentPicIndex + ((whichSite == "us") ? " of " : " / ") + lastPicIndex + "</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id=\"nextLink\"><a href=\"javascript:switchPic(1, '" + whichSite + "');\">" + strNext + " &gt;&gt;</a></span></div></td></tr></table></body></html>";
	var picWindow = window.open("#", numWindows++, "directories=no,toolbar=no,menubar=no,location=no,menubar=no,scrollbars=no,resizable=no,status=no,width=830,height=640");
	picWindow.document.write(tempStr);
}

function switchPic(direction, whichSite) {
	document["bigPic"].src = "http://www.nzone.com/docs/IO/10274/img10274.gif";	// shim
	if (currentPicIndex == lastPicIndex && direction)
		currentPicIndex = 1;
	else if (currentPicIndex == 1 && !direction)
		currentPicIndex = lastPicIndex;
	else
		currentPicIndex += (direction) ? 1 : -1;
	document["bigPic"].src = path + imageNamePrefix + currentPicIndex + ".jpg";
	document.getElementById("caption").innerHTML = (typeof(opener.captions) != "undefined" && typeof(opener.captions[currentPicIndex]) != "undefined") ? opener.captions[currentPicIndex] : "";
	document.getElementById("status").innerHTML = currentPicIndex + ((whichSite == "us") ? " of " : " / ") + lastPicIndex;

}

function blinkDropDownBackground(times) {
	document.getElementById("gamesDropDown").style.backgroundColor = (times % 2) ? "#77AA00" : "#2D3038";
	document.getElementById("gamesDropDown").style.color = (times % 2) ? "#000000" : "#FFFFFF";
	if (times > 0)
		setTimeout("blinkDropDownBackground(" + (times - 1) + ")", 125);
}

function launchVideo(width, height, type, url) {
	var startStr = "<html><body style='margin: 2px; color: #FFFFFF; background-color: #000000;'><table width=\"100%\" height=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr valign=\"center\"><td align=\"center\">"
	var WMV = "<object classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112\"><param name=\"autosize\" value=\"0\"><param name=\"autostart\" value=\"1\"><param name=\"displaybackcolor\" value=\"black\"><param name=\"name\" value=\"WMP\"><param name=\"showcontrols\" value=\"0\"><param name=\"showstatusbar\" value=\"1\"><param name=\"src\" value=\"" + url + "\"><embed autosize=\"0\" autostart=\"1\" displaybackcolor=\"black\" name=\"WMP\" showcontrols=\"0\" showstatusbar=\"1\"width=\"" + width + "\"height=\"" + height + "\"src=\"" + url + "\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\"type=\"video/x-ms-asf-plugin\"></object>";
	var endStr = "</td></tr></table></body></html>";
	var videoWindow = window.open("#", numWindows++, "directories=no,toolbar=no,menubar=no,location=no,menubar=no,scrollbars=no,resizable=no,status=no,width=" + (width + 20) + ",height=" + (height + 35));
	videoWindow.document.write(startStr + eval(type) + endStr);
}

function sendToGame(selectBox) {
	var newgame = selectBox.options[selectBox.selectedIndex].value;
	if (newgame != '')
		location.href = newgame;
}

var onLoadList = new Array("browserCorrections();");
function init() {
	for (var i = 0; i < onLoadList.length; i++)
		eval(onLoadList[i]);
}

function browserCorrections() {
	if (Opera && document.getElementById("divScreenshotsBox") != null)
		document.getElementById("divScreenshotsBox").style.marginLeft = "-3px";
	if (Opera && document.getElementById("divComingSoonBox") != null)
		document.getElementById("divComingSoonBox").style.marginLeft = "-3px";
}

function startCalendarTable() {
	var tempStr = "<table cellpadding=\"0\" cellspacing=\"0\" class=\"calendar\" style=\"width: 574px; border: 1px solid #0B7F8B; border-collapse: collapse; background: #12233B url(/docs/TEMPLATE/110/calendar_bg.jpg) no-repeat scroll 0px ";
	if (NS6 || NS7 || Mozilla)
	     tempStr += "-18px;";
	else if (Opera)
	     tempStr += "-12px;";
	else
 	    tempStr += "-13px;";
	tempStr += "\">\n";
	document.write(tempStr);
}

function onClickEvents() {
	var today = new Date();
	var monthName;
	switch (today.getMonth()) {
		case 0: monthName = "january"; break;
		case 1: monthName = "february"; break;
		case 2: monthName = "march"; break;
		case 3: monthName = "april"; break;
		case 4: monthName = "may"; break;
		case 5: monthName = "june"; break;
		case 6: monthName = "july"; break;
		case 7: monthName = "august"; break;
		case 8: monthName = "september"; break;
		case 9: monthName = "october"; break;
		case 10: monthName = "november"; break;
		case 11: monthName = "december"; break;
	}
	location.href = "/object/nzone_calendar_" + monthName + today.getFullYear() + ".html";
}

// IE & NS use different sort algorithms. Use this for consistency. 
// Takes any number of field argument strings after array & direction, will sort each in turn
// direction: 0 = descending, 1 = ascending
function sortBy(arrayToSort, direction) {	
	for (var h = 2; h < arguments.length; h++)
		for (var i = arrayToSort.length - 2; i >= 0; i--)
			for (var j = 0; j <= i; j++)
				if (direction == 0 && eval("arrayToSort[j + 1]." + arguments[h]) > eval("arrayToSort[j]." + arguments[h])) {
					var tempElement = arrayToSort[j];
					arrayToSort[j] = arrayToSort[j + 1];
					arrayToSort[j + 1] = tempElement;
				} else if (direction == 1 && eval("arrayToSort[j + 1]." + arguments[h]) < eval("arrayToSort[j]." + arguments[h])) {
					var tempElement = arrayToSort[j];
					arrayToSort[j] = arrayToSort[j + 1];
					arrayToSort[j + 1] = tempElement;
				}
}

function openGlossary(alias){
	newwin = window.open("http://www.nvidia.com/object/" + alias + ".html?_templateId=13", "GlossaryWindow", "toolbar=no,status=no,width=266,height=216,directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no");
	newwin.focus();
}

function changeInnerHtml(strId, newInnerHtml) {
	if (NS4) {
		eval(layerRef + "[\"" + strId + "\"].document.open();");
		eval(layerRef + "[\"" + strId + "\"].document.write(newInnerHtml);");
		eval(layerRef + "[\"" + strId + "\"].document.close();");
	} else if (NS6 || NS7 || Mozilla)
		eval(layerRef + "(\"" + strId + "\").innerHTML = newInnerHtml;");
	else
		eval(layerRef + "[\"" + strId + "\"].innerHTML = newInnerHtml;");
}		

// custom objects
GameLink = function (title, url) {
	this.title = title;
	this.url = url;
}

Game = function (title, url_banner, url_site, url_nzone, quote, byLine) {
	this.title = title;
	this.url_banner = url_banner;
	this.url_site = url_site;
	this.url_nzone = url_nzone;
	this.quote = quote;				// only used for first game in an array
	this.byLine = byLine;			// only used for first game in an array
}

Company = function (name, url_smallLogo, url_bigLogo, url_site, description, quote, byLine, games) {
	this.name = name;
	this.url_smallLogo = url_smallLogo;
	this.url_bigLogo = url_bigLogo;
	this.url_site = url_site;
	this.description = description;
	this.quote = quote;
	this.byLine = byLine
	this.games = games;
}

TransporterGenerator = function (publishers, developers, text_TWIMTBP_game, text_TWIMTBP_publisher, text_TWIMTBP_developer) {
	this.publishers = publishers;
	this.developers = developers;
	this.text_TWIMTBP_game = text_TWIMTBP_game;
	this.text_TWIMTBP_publisher = text_TWIMTBP_publisher;
	this.text_TWIMTBP_developer = text_TWIMTBP_developer;

	this.transportWindow = null;
	this.windowOptions = "directories=no,toolbar=no,menubar=no,location=no,menubar=no,,scrollbars=yes,resizable=yes,status=no,width=660,height=620";

	this.common_1 = "<html><head><base href=\"http://www.nvidia.com\"><style type=\"text/css\">@import \"/docs/TEMPLATE/112/nzone_global.css\";</style><scr" + "ipt language=\"JavaScript\" type=\"text/javascript\" src=\"/docs/TEMPLATE/112/nzone_global.js\"></scr" + "ipt></head><body><table cellpadding=\"0\" cellspacing=\"0\" height=\"100%\" width=\"100%\"><tr valign=\"center\"><td align=\"center\"><table height=\"1\" width=\"629\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr height=\"16\"><td colspan=\"3\"><img height=\"16\" width=\"629\" src=\"/docs/TEMPLATE/110/top6.gif\"></td></tr><tr valign=\"top\"><td background=\"/docs/TEMPLATE/110/gray_line7.gif\" width=\"3\"><img height=\"1\" width=\"3\" src=\"/docs/TEMPLATE/110/shim.gif\"></td><td width=\"606\" bgcolor=\"#0B1121\"><div id=\"content\" style=\"margin: 5px 9px 5px 9px;\" class=\"gameNormal\">";
}

TransporterGenerator.prototype.commonFinish = function () {
	var tempStr = "</td><td width=\"20\" valign=\"bottom\"";
	if (NS6 || NS7 || Opera || Mozilla)
		tempStr += " background=\"/docs/TEMPLATE/110/right5_ns_op_moz.gif\"";
	tempStr += "><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"100%\"><tr height=\"16\"><td><img src=\"/docs/TEMPLATE/110/";
	if (NS6 || Opera || Mozilla)
		tempStr += "right5_ns_op_moz.gif";
	else
		tempStr += "right5.gif";
	tempStr += "\" width=\"20\" height=\"16\"></td></tr>";
	if (!(NS6 || Opera))
		tempStr += "<tr height=\"100%\"><td background=\"/docs/TEMPLATE/110/right6.gif\">"
				+ "<img src=\"/docs/TEMPLATE/110/shim.gif\" width=\"20\" height=\"1\"/></td></tr>";
	tempStr += "<tr height=\"117\"><td><img src=\"/docs/TEMPLATE/110/right7";
	if (NS6 || Opera)
		tempStr += "_ns_op";
	tempStr += ".gif\" width=\"20\" height=\"117\"></td></tr></table></td></tr><tr height=\"15\"><td colspan=\"3\">"
			+ "<img height=\"15\" width=\"629\" src=\"/docs/TEMPLATE/110/bottom7.gif\"></td></tr></table></td></tr></table></body></html>";
	return tempStr;
}

TransporterGenerator.prototype.companyTransport = function (which) {
	var companyType = which.substr(0, 9);
	var companyIndex = (which.substr(9)) ? which.substr(9) - 1 : 0;
	var company = eval("this." + companyType + "s[" + companyIndex + "]");

	var tempStr;
	// company logo (if present) and description
	if (company.url_bigLogo || company.url_smallLogo) {
		tempStr = "<table width=\"585\" cellspacing=\"0\" cellpadding=\"0\"><tr valign=\"top\"><td width=\"195\" align=\"center\"><div class=\"gameNormal\">"
				+ "<a href=\"javascript:window.open('" + company.url_site + "'); window.close();\"><img src=\"" 
				+ ((company.url_bigLogo) ? company.url_bigLogo : company.url_smallLogo) + "\" border=\"0\" vspace=\"4\"><br clear=\"all\">"
				+ "Click to Visit Website</a></div></td><td width=\"390\"><div class=\"gameNormal\"><b>" + company.name + "</b><br>" + company.description 
				+ "</div></td></tr></table>";
	} else
		tempStr = "<div style=\"margin: 0px 18px 0px 18px;\"><a href=\"javascript:opener.location.href = '" + company.url_site + "'; window.close();\">" 
				+ "<b>" + company.name + "</b></a><br><br style=\"line-height: 4px;\">" + company.description + "</div>";

	// company quote
	if (company.quote != "" && company.byLine != "")
		tempStr += "<hr><div style=\"margin: 0px 10px 2px 10px\"><i>" + company.quote + "</i><div align=\"right\">&#151; " + company.byLine + "</div></div>";

	tempStr += "<div align=\"center\">";
	// game banners
	for (var i= 0; i < company.games.length; i++)
		if (company.games[i].url_banner != "")
			tempStr += "<hr><a href=\"javascript:opener.location.href = '" + company.games[i].url_nzone + "'; window.close();\"><img src=\"" 
					+ company.games[i].url_banner + "\" style=\"border: 1px solid #444444;\"></a>";

	var messagingText = eval("this.text_TWIMTBP_" + companyType);
	if (messagingText != "")
		messagingText = "<hr>" + messagingText;
	tempStr += "</div>" + messagingText + "</div>";

	if (this.transportWindow && !this.transportWindow.closed)
		this.transportWindow.document.getElementById("content").innerHTML = tempStr;
	else {
		this.transportWindow = window.open("#", numWindows++, this.windowOptions);
		this.transportWindow.document.write(this.common_1 + tempStr + this.commonFinish());
		if (Opera)	// silly Opera bug
			this.transportWindow.document.write("<br>");
	}
	this.transportWindow.document.title = "nZone " + company.name + " Site Transport";
	this.transportWindow.focus();

	window.onunload = function() { 
		transporter.transportWindow.close();
	}
}

TransporterGenerator.prototype.gameTransport = function () {
	function companyTables(companyType) {
		var companyArray = eval(companyType + "s");
		for (var i = 0; i < companyArray.length; i++) {
			var company = companyArray[i];
			if (company.url_smallLogo != "" || company.url_site != "" || company.description) {
				if (companyType != "developer" || i < companyArray.length - 1)
					tempStr += "<div style=\"margin-bottom: 8px;\">";
				tempStr += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"585\">";
				if (company.url_smallLogo != "" || company.description != "") {
					tempStr += "<tr valign=\"top\"><td width=\"150\" align=\"center\">\n\n";
					if (company.url_smallLogo != "")
						tempStr += "<a href=\"javascript:opener.transporter.companyTransport('" + companyType + ((i) ? i + 1 : "") + "');\"><img src=\"" 
								+ company.url_smallLogo + "\" vspace=\"5\" border=\"0\"></a>";
					else
						tempStr += "<div class=\"gameNormal\" style=\"margin-left: 10px; font-weight: bold;\">"
								+ "<a href=\"javascript:opener.transporter.companyTransport('" + companyType + ((i) ? i + 1 : "") + "');\">" + company.name + "</a></div>";
					tempStr += "</td><td width=\"435\">";
					if (company.description != "") 
						tempStr += "<div class=\"gameNormal\"><div style=\"font-weight: bold;\">" + company.name + "</div>" + company.description + "</div>";
					tempStr += "</td></tr>";
				}
				tempStr += "</table>";
				if (companyType != "developer" || i < companyArray.length - 1)
					tempStr += "</div>";
			}
		}
	}

	var publishers = this.publishers;
	var developers = this.developers;

	var game;
	for (var i = 0; i < publishers[0].games.length; i++)
		if (publishers[0].games[i].title == document.title) {
			game = publishers[0].games[i];
			break;
		}

	//TODO: remove this debug line
	//game = publishers[0].games[0];

	// banner and text linkage
	var tempStr = "<div align=\"center\" style=\"margin-top: 3px; margin-bottom: 10px;\">"
				+ "<a href=\"javascript:window.open('" + game.url_site + "'); window.close();\">";
	if (game.url_banner != "")
		tempStr += "<img style=\"border: 1px solid #444444;\" src=\"" + game.url_banner + "\" vspace=\"5\" border=\"0\"><br>";
	tempStr += "Click to Visit Website</a></div>";
	
	// game quote
	if (game.quote != "" && game.byLine != "")
		tempStr += "<div style=\"margin: 0px 10px 2px 10px\"><i>" + game.quote + "</i><div align=\"right\">&#151; " + game.byLine + "</div></div>";
	
	tempStr += "<hr>";

	companyTables("publisher");
	companyTables("developer");

	var messagingText = this.text_TWIMTBP_game;
	if (messagingText != "")
		messagingText = "<hr>" + messagingText;
	tempStr += messagingText + "</div>";
	
	if (this.transportWindow && !this.transportWindow.closed)
		this.transportWindow.document.getElementById("content").innerHTML = tempStr;
	else {
		this.transportWindow = window.open("#", numWindows++, this.windowOptions);
		this.transportWindow.document.write(this.common_1 + tempStr + this.commonFinish());
		if (Opera)	// silly Opera bug
			this.transportWindow.document.write("<br>");
	}
	this.transportWindow.document.title = "nZone " + game.title + " Offical Game Site Transport";
	this.transportWindow.focus();
	
	window.onunload = function() { 
		transporter.transportWindow.close();
	}
}