

/*//////////////////////////////////////////////////////////////////////////////
////                                                                        ////
////  All scripts contained within this file are the copyrighted works of   ////
////   VFX Digital Solutions, Inc., Championship Auto Racing Teams, Inc.    ////
////                         (CART), and CART.com.                          ////
////                                                                        ////
////                        Copyright (C)                          ////
////  VFX Digital Solutions, Inc. and Championship Auto Racing Teams, Inc.  ////
////                          All rights reserved.                          ////
////                                                                        ////
//////////////////////////////////////////////////////////////////////////////*/

var user_agent = navigator.userAgent.toLowerCase();
var isMajor = parseInt(navigator.appVersion);
var isMinor = parseFloat(navigator.appVersion);

var isIE  = ((user_agent.indexOf("msie") != -1) && (user_agent.indexOf("opera") == -1));
var isIE3 = (isIE && (isMajor < 4));
var isIE4 = (isIE && (isMajor == 4) && (user_agent.indexOf("msie 4") != -1));
var isIE4up = (isIE && (isMajor >= 4));
var isIE5 = (isIE && (isMajor == 4) && (user_agent.indexOf("msie 5.0") != -1));
var isIE55 = (isIE && (isMajor == 4) && (user_agent.indexOf("msie 5.5") != -1));
var isIE6 = (isIE && (isMajor == 4) && (user_agent.indexOf("msie 6.") != -1));
var isIE6up = (isIE && !isIE3 && !isIE4 && !isIE5 && !isIE55);

var isSafari = (user_agent.indexOf("safari") != -1)

//	var isIE4 = (document.all) ? true : false;
var isNN4 = (document.layers) ? true : false;
var isNN6 = ((document.getElementById || isSafari) && (!isIE4)) ? true : false;
var isMac = (user_agent.indexOf('mac') != -1)
var ieHasFilters = false;

var imagesLoaded = false;

var timing_window = 0;
var mediaplayer_window = 1;
var custom_window = 3;
var contest_window = 4;
var pdf_window = 5;
var photo_window = 6;
var print_window = 7;
var telemetry_window = 8;
var speedOnDemand_window = 9;
var localization_window = 10;
	
// window opener		
function openWindow(value)
{
	var winObj = new Object();
	winObj.name = "";
	winObj.URL = "";
	winObj.properties = "";
		
	switch (value)
	{
		case 0:
			// timing_window
			winObj.URL = "http://leaderboard.vfx.com/ChampCar/LiveTiming_800.asp";
			winObj.name = "TimingWin";
			winObj.properties = "width=780,height=530,resizable=yes,scrollbars=yes,status=no,location=no,toolbar=no,directories=no,menubar=no";
			break;
				
		case 1:
			// mediaplayer_window
			winObj.URL = "/embeddedplayer/default.asp?" + openWindow.arguments[1];
			winObj.name = "MediaPlayerWin";
			winObj.properties = "width=628,height=424,resizable=no,scrollbars=auto,status=no,location=no,toolbar=no,directories=no,menubar=no";
			break;
				
		case 2:
			// live show player
			break;
			
		case 3:
			// custom_window
			winObj.URL = openWindow.arguments[1];
			winObj.name = openWindow.arguments[2];
			winObj.properties = openWindow.arguments[3];
			break;
				
		case 4:
			// contest_window
			winObj.URL = "/d101/";
			winObj.name = "ContestWin";
			winObj.properties = "width=788,height=544,resizable=yes,scrollbars=auto,menubar=no,location=no,toolbar=no,directories=no,status=no";
			break;
				
		case 5:
			// pdf_window
			winObj.URL = openWindow.arguments[1];
			winObj.name = "PDFWin";
			winObj.properties = "width=788,height=544,resizable=yes,scrollbars=no,menubar=no,location=no,toolbar=no,directories=no,status=no";
			break;
				
		case 6:
			// photo_window
			winObj.URL = "/PhotoPopup.asp?ID=" + openWindow.arguments[1];
			winObj.name = "PhotoWin";
			winObj.properties = "width=500,height=450,resizable=yes,scrollbars=yes,menubar=no,location=no,toolbar=no,directories=no,status=no";
			break;
				
		case 7:
			// print_window
			winObj.URL = openWindow.arguments[1];
			winObj.name = "PrintWin";
			winObj.properties = "width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes";
			break;
				
		case 8:
			// telemetry window
			winObj.URL = "/Event/TelemetryMap.asp?ID=" + openWindow.arguments[1];
			winObj.name = "TelemetryWin";
			winObj.properties = "resizable=yes,status=no,scrollbars=no,location=no,toolar=no,direcories=no,menubar=no,width=550,height=550";
			break;
				
		case 9:
			// speed on demand window
			winObj.URL = "/EmbeddedPlayer/SPEED";
			winObj.name = "SPEEDWin";
			winObj.properties = "width=628,height=424,resizable=no,scrollbars=auto,status=no,location=no,toolbar=no,directories=no,menubar=no";
			break;
			
		case 10:
			// localization
			winObj.URL = "/Scripts/Localization.asp";
			winObj.name = "LocalizationWin";
			winObj.properties = "width=200,height=100,resizable=no,scrollbars=no,status=no,location=no,toolbar=no,directories=no,menubar=no";
			break;
	}
		
	if (winObj.URL != "")
	{
		var myWin = window.open(winObj.URL, winObj.name, winObj.properties);
		myWin.focus();
		return false;
	}
}

function getCookie(name)
{
	var dc = document.cookie;
	var pre = name + "=";
	var b = dc.indexOf("; " + pre);
	if (b == -1)
	{
		b = dc.indexOf(pre);
		if (b != 0) return null;
	}
	else
	{
		b += 2;
	}
	var e = document.cookie.indexOf(";", b);
	if (e == -1) e = dc.length;
	return unescape(dc.substring(b + pre.length, e));
}
		
function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}
		
function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-69 00:00:01 GMT";
	}
}


var imageIndex = new Array();
var imageArray = new Array();
var tempImageArray = new Array();

function addImageIndex(imageName, imageSource)
{
	var tempArrayLength = tempImageArray.length;
	imageIndex[imageName] = tempArrayLength;
	tempImageArray[tempArrayLength] = imageSource;
}

function swapImage(imageObj, imageName)
{
	if (imagesLoaded)
	{
		document.images[imageObj].src = imageArray[imageIndex[imageName]].src;
	}	
}

function swapImages()
{
	if (imagesLoaded)
	{
		for (i = 0; i < swapImages.arguments.length; i += 2)
		{
			var docImages = document.images[swapImages.arguments[i]];
			docImages.src = imagesArray[imageIndex[swapImages.arguments[i + 1]]].src;
		}
	}
}

function getImages()
{
	if (document.images)
	{
		for (i = 0; i < tempImageArray.length; i++)
		{
			imageArray[i] = new Image();
			imageArray[i].src = tempImageArray[i];
		}
		imagesLoaded = true;
	}
}

function choreograph()
{
	getImages();
}