// system globals
var highestVersion = 10;	// highest version we can actually detect
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

function flashObject(){
	this.highestVersion=highestVersion; // Change this to highest version available
	this.isFlashInstalled=isFlashInstalled;
	this.getFlashVersion=getFlashVersion;
	this.setFlashPage=setFlashPage;
	this.setNonFlashPage=setNonFlashPage;
	this.setUpgradeFlashPage=setUpgradeFlashPage;
	this.flashVersionThroughVBscript=flashVersionThroughVBscript; // for IE on windows

	this.flashInstalled=false;
	this.flashVersion=0;
}

function isFlashInstalled(){
	var flashVersion = this.getFlashVersion();
	var returnVal=(flashVersion>7)?true:false;
	this.flashInstalled=returnVal;
	return returnVal;
}

function getFlashVersion(){
	var flashVersionX	= 0;
	var flashVersion	= 0;
	if (navigator.plugins){
		if (navigator.plugins["Shockwave Flash 2.0"] 	// yes>> then is Flash 2
		|| navigator.plugins["Shockwave Flash"]){		// or flash 3+ installed?
			// set convenient references to flash 2 and the plugin description
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			// a flash plugin-description looks like this: Shockwave Flash 4.0 r5
		 flashVersionX	= parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 2));
		 if (flashVersionX>0) {
			flashVersion = parseInt(flashVersionX+""+flashVersion);
		 } else {
			flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		 }

		}else{
			if(isIE && isWin){ // don't write vbscript tags on anything but ie win
				flashVersion=this.flashVersionThroughVBscript();
			}
		}
	}
	// if we're on webtv, the version supported is 2 (pre-summer2000, or 3, post-summer2000)
	if(navigator.userAgent.indexOf("WebTV") != -1) flashVersion = 2;
	this.flashVersion=flashVersion;
	return flashVersion;
}

function flashVersionThroughVBscript(){
	 var flashVersion=0;
	 // VERY IMPORTANT
	 // these are global so that same variables can be shared between
	 // VBscript and Javascript
	 flash2Installed = false;		// boolean. true if flash 2 is installed
	 flash3Installed = false;		// boolean. true if flash 3 is installed
	 flash4Installed = false;		// boolean. true if flash 4 is installed
	 flash5Installed = false;		// boolean. true if flash 5 is installed
	 flash6Installed = false;		// boolean. true if flash 6 is installed
	 flash7Installed = false;		// boolean. true if flash 7 is installed
	 flash8Installed = false;		// boolean. true if flash 8 is installed
	 flash9Installed = false;		// boolean. true if flash 9 is installed
	 flash10Installed = false;		// boolean. true if flash 10 is installed
	// write vbscript detection if we're not on mac.
	if(isIE && isWin){ // don't write vbscript tags on anything but ie win
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
		document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
		document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
		document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
		document.write('flash10Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.10"))) \n');
		document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	}
	if(isIE && isWin){ // don't write vbscript tags on anything but ie win
		for (var i = 2; i <= this.highestVersion; i++) {
			if (eval("flash" + i + "Installed") == true) flashVersion = i;
		}
	}
	return flashVersion;
}

// javascript should be >=1.1 otherwise replace command wont work.
function setFlashPage(flashPageURL,targetFrame){
	if(this.flashInstalled){
		if(targetFrame){
			targetFrame.location.replace(flashPageURL);
		}else{
			window.location.replace(flashPageURL);
		}
	}
}

function setNonFlashPage(nonFlashPageURL,targetFrame){
	if(!this.flashInstalled){
		if(targetFrame){
			targetFrame.location.replace(nonFlashPageURL);
		}else{
			window.location.replace(nonFlashPageURL);
		}
	}
}

function setUpgradeFlashPage(upgradeFlashPageURL,targetFrame,requiredVersion){
	if(this.flashInstalled && requiredVersion >this.flashVersion){
		if(targetFrame){
			targetFrame.location.replace(upgradeFlashPageURL);
		}else{
			window.location.replace(upgradeFlashPageURL);
		}
	}
}

var flashobj=new flashObject();
var flashInstalled=flashobj.isFlashInstalled();

