// Adapted from ESPN Flash Detection script by Danny Mavromatis 4/20/06 Lawrence & Schiller
var cId = 0;
var mV = 8;
var aV = 0;
var hRV = false;
var jsV = 1.1;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

if(isIE && isWin) {
	document.write('<scr' + 'ipt language=VBScript\> \n');
	document.write('Function VBGetSwfVer(i) \n');
	document.write('on error resume next \n');
	document.write('Dim swControl, swVersion \n');
	document.write('swVersion = 0 \n');
	document.write('set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) \n');
	document.write('if (IsObject(swControl)) then \n');
	document.write('swVersion = swControl.GetVariable("$version") \n');
	document.write('end if \n');
	document.write('VBGetSwfVer = swVersion \n');
	document.write('End Function \n');
	document.write('</scr' + 'ipt\> \n');
}

// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
				descArray = flashDescription.split(" ");
				tempArrayMajor = descArray[2].split(".");
				versionMajor = tempArrayMajor[0];
			if ( descArray[3] != "" ) {
			      tempArrayMinor = descArray[3].split("r");
			} else {
			      tempArrayMinor = descArray[4].split("r");
			}
			      versionMinor = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			      flashVer = parseFloat(versionMajor + "." + versionMinor);
		} else {
		      flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
	      flashVer = -1;
	}
	return flashVer;
}

function DetectFlashVer(reqMajorVer, reqMinorVer) {
	reqVer = parseFloat(reqMajorVer + "." + reqMinorVer);
	var ua=navigator.userAgent.toLowerCase();
	this.webtv = (ua.indexOf("webtv")>-1);
	this.ie = (parseFloat(ua.slice(ua.indexOf("msie")+5)));
	this.nn = (parseFloat(ua.slice(ua.indexOf("mozilla/")+8)));
	var browser = navigator.appName.toLowerCase();
	if (browser=="netscape"){
		this.netscape = true;
	}else{
		this.netscape = false;
	}
	this.mac = (ua.indexOf("mac")>-1);
	this.opera = (ua.indexOf("opera")>-1);
	this.flash = false;
	// loop backwards through the versions until we find the newest version      
	for (i=reqMajorVer;i>0;i--) {
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		}
		else {
			versionStr = JSGetSwfVer(i);
		}
		if (versionStr == -1) {
			this.flash = 0;
		}
		else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray = versionStr.split(" ");
				tempString = tempArray[1];
				versionArray = tempString .split(",");
				versionMajor = versionArray[0];
				versionMinor = versionArray[2];
				versionString = versionMajor + "." + versionMinor;
				versionNum = parseFloat(versionString);
			}
			else {
				versionNum = versionStr;
			}
			if (versionNum >= reqVer) {
				this.flash = true;
				break;
			} else {
				this.flash = false;
			}
		}
	}
}

function flashObj() {
	cId += 1;
	this.flashFile = "flash/blank.swf";
	this.LiveConnect = "FALSE";
	this.IEonly = null;
   	this.wmode = "opaque";
   	this.redirect = null;
	this.DenyIEdl = "FALSE";
	this.altImg = "blank.gif"; 
	this.bgcolor = null;
	this.altTxt = null;
	this.height = "400";
	this.width = "520";
	this.salign="lt";
	this.align="left";
	this.flashVars = null;
	this.ID = "flash"+ cId;
	this.name = "flash"+ cId;
	this.webTV = "true";
	this.quality = "best";
	this.scale = "exactfit";
	this.menu = "false";
	this.deviceFont = "false";
	this.FlashVer = 5;
	this.cabVersion = "5,0,0,0";
	this.http = 0;
	this.render = writeFlashComponent;
}

function writeFlashComponent(val) {
	var Ticket=new DetectFlashVer(this.FlashVer,0);
	var sCR;
	if (Ticket.flash) {
		if (Ticket.mac || Ticket.netscape || Ticket.opera) {
			sCR='<embed src="'+this.flashFile+'" swLiveConnect="'+this.LiveConnect+'" width="'+this.width+'" height="'+this.height+'" quality="'+this.quality+'" scale="'+this.scale+'" flashvars="'+ this.flashVars +'" wmode="'+this.wmode+'" id="'+this.ID+'" name="'+this.name+'" menu="'+this.menu+'" devicefont="'+this.deviceFont + '"';
			if (this.bgcolor) {
				sCR += ' bgcolor="'+this.bgcolor + '"';
			}
			if (this.salign) {
				sCR += ' salign="'+this.salign + '"';
			}
			sCR += ' type="application/x-shockwave-flash" pluginspage="'+this.http+'://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
		} else if (this.DenyIEdl=='TRUE') {
			sCR="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\""+this.http+"://active.macromedia.com/flash2/cabs/swflash.cab#version="+this.FlashVer+",0,0,0\" id=\""+this.ID+"\" width=\""+this.width+"\" height=\""+this.height+"\">\n";
			sCR+="<param name=movie value=\""+this.flashFile+"\">\n";						
			sCR+="<param name=quality value=\""+this.quality+"\">\n";
			sCR+="<param name=scale value=\""+this.scale+"\">\n";
			sCR+="<param name=menu value=\""+this.menu+"\">\n";
			sCR+="<param name=wmode value=\""+this.wmode+"\">\n";
			if (this.bgcolor){
				sCR+="<param name=bgcolor value=\""+this.bgcolor+"\">\n";
			}
			if (this.flashVars){
				sCR+="<param name=FlashVars value=\""+this.flashVars+"\">\n";
			}
			if (this.salign) {
				sCR+="<param name=salign value=\""+this.salign+"\">\n";
			}
			sCR+="<param name=devicefont value=\""+this.deviceFont+"\">\n";
			if (this.bgcolor){
			sCR+="<embed src="+this.flashFile+" swLiveConnect="+this.LiveConnect+" width="+this.width+" height="+this.height+" quality="+this.quality+" scale="+this.scale+" wmode="+this.wmode+" id="+this.ID+" name="+this.name+" menu="+this.menu+" devicefont="+this.deviceFont+" flashvars="+ this.flashVars +" bgcolor="+this.bgcolor+" type=application/x-shockwave-flash pluginspage="+this.http+"://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash></embed></object>";
			} else {
			sCR+="<embed src="+this.flashFile+" swLiveConnect="+this.LiveConnect+" width="+this.width+" height="+this.height+" quality="+this.quality+" scale="+this.scale+" wmode="+this.wmode+" id="+this.ID+" name="+this.name+" menu="+this.menu+" devicefont="+this.deviceFont+" flashvars="+ this.flashVars +" type=application/x-shockwave-flash pluginspage="+this.http+"://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash></embed></object>";
			}
		} else if (Ticket.ie>=4 && this.DenyIEdl=='FALSE') {
			sCR="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\""+this.http+"://active.macromedia.com/flash2/cabs/swflash.cab#version="+this.cabVersion+"\" id=\""+this.ID+"\" width=\""+this.width+"\" height=\""+this.height+"\">\n";
			sCR+="<param name=movie value=\""+this.flashFile+"\">\n";						
			sCR+="<param name=quality value=\""+this.quality+"\">\n";
			sCR+="<param name=scale value=\""+this.scale+"\">\n";
			sCR+="<param name=menu value=\""+this.menu+"\">\n";
			sCR+="<param name=wmode value=\""+this.wmode+"\">\n";
			if (this.flashVars){
				sCR+="<param name=FlashVars value=\""+this.flashVars+"\">\n";
			}
			if (this.bgcolor){
				sCR+="<param name=bgcolor value=\""+this.bgcolor+"\">\n";
			}
			if (this.salign) {
				sCR+="<param name=salign value=\""+this.salign+"\">\n";
			}
			sCR+="<param name=devicefont value=\""+this.deviceFont+"\">\n";
			sCR+="</object>\n";
		} else if (Ticket.webtv) {
			sCR="<embed src="+this.flashFile+" swLiveConnect=TRUE width="+this.width+" height="+this.height+" quality="+this.quality+" scale="+this.scale+" wmode="+this.wmode+" id="+this.ID+" name="+this.name+" menu="+this.menu+" devicefont="+this.deviceFont+" flashvars="+ this.flashVars +" type=application/x-shockwave-flash pluginspage="+this.http+"://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash></embed>";
		}
	}
	else
	{
		if (this.redirect) {
		 	top.location.href = this.redirect;
		}
		else {
			sCR = this.altTxt;
		}
	}
	
	if (val == true) {
		document.write(sCR);
	} 
	else {
		return sCR;
	}
}
