/**
* @author		Jan van der Veen
* @date			2006-05-12
* @description	This script accurately detects the whether the user has a Flash plug-in	installed
*				in their browser and if so, returns the version number. This script was based on
*				Macromedia's Flash Player Detection Kit. For more information see
*				http://www.adobe.com/products/flashplayer/download/detection_kit/
*/

// Create the namespaces used by the classes
if (typeof venspro == "undefined"){
	venspro = new Object;	
}
if (typeof venspro.flash == "undefined"){
	venspro.flash = new Object();
}
if (typeof venspro.flash.detection == "undefined"){
	venspro.flash.detection = new Object();
}

// Create the FlashDetector constructor
venspro.flash.detection.FlashPluginDetector = function(){
	this.detected = false;
	this.isIE = false;
	this.isWin = false;
	this.isOpera = false;
}

// Create the methods for the SwfObject
venspro.flash.detection.FlashPluginDetector.prototype = {
	
	// Detects the browser version in order to perform specific filtering
	detect: function(){
		//alert("detect()")
		this.detected = true;
		this.isIE = (navigator.appVersion.indexOf("MSIE") != -1);
		this.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1);
		this.isOpera = (navigator.userAgent.indexOf("Opera") != -1);
	},
	
	// Gets the version of the Flash player using the ActiveX control
	getControlVersion: function(){
		//alert("getControlVersion");
		if (!this.detected)
		{
			this.detect();	
		}
		var version;
		var axo;
		var e;
		
		// Check for Flash Player 7 and up
		try
		{
			// Version will be set for 7.x or newer players
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			version = axo.GetVariable("$version");
		}
		catch(e){}
		
		// Check for Flash Player 6
		if (!version)
		{
			try
			{
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				
				// The installed version is some revision of 6.0
				// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29.
				
				// Default to the first public version
				version = "WIN 6,0,21,0";
	
				// Throws an error if AllowScripAccess does not exist (introduced in 6.0r47)		
				axo.AllowScriptAccess = "always";
	
				// Safe to call for 6.0r47 or greater
				version = axo.GetVariable("$version");
			}
			catch (e){}
		}
		
		// Check for Flash Player 5 and 4
		if (!version)
		{
			try
			{
				// Version will be set for 4.x or 5.x players
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				
				// Throws an error is GetVariable does not exist (introduced in 4.0)
				version = axo.GetVariable("$version");
			}
			catch (e){}
		}
		
		// Check for Flash Player 3
		if (!version)
		{
			try
			{
				// Version will be set for 3.x players
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				version = "WIN 3,0,18,0";
			}
			catch (e){}
		}
		
		// Check for Flash Player 2
		if (!version)
		{
			try
			{
				// Version will be set for 2.x players
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				version = "WIN 2,0,0,11";
			}
			catch (e)
			{
				// Set the version to -1 to indicate the version could not be detected
				version = -1;
			}
		}
		return version;
	},
	
	// Returns the Flash version as a string
	getFlashVersion: function(){
		//alert("getFlashVersion");
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		var flashVer = -1;
		if (!this.detected)
		{
			this.detect();	
		}
		
		if (navigator.plugins != null && navigator.plugins.length > 0)
		{
			var flashDescription = "";
			if (navigator.plugins["Shockwave Flash 2.0"])
			{
				//alert("navigator.plugins[Shockwave Flash 2.0]")
				flashDescription = navigator.plugins["Shockwave Flash 2.0"].description;
			}
			else if (navigator.plugins["Shockwave Flash"])
			{
				//alert("navigator.plugins[Shockwave Flash]")
				flashDescription = navigator.plugins["Shockwave Flash"].description;
			}
			//alert("flashDescription = "+flashDescription);
			if (flashDescription != "")
			{
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" )
				{
					tempArrayMinor = descArray[3].split("r");
				}
				else
				{
					tempArrayMinor = descArray[4].split("r");
				}
				var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}		
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1)
		{
			// MSN/WebTV 2.6 supports Flash 4
			flashVer = 4;
		}
		
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1)
		{
			// WebTV 2.5 supports Flash 3
			flashVer = 3;
		}
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1)
		{
			// Older WebTV supports Flash 2
			flashVer = 2;
		}else if ( this.isIE && this.isWin && !this.isOpera )
		{
			flashVer = this.getControlVersion();
		}
		//alert("Return value: "+flashVer)
		return flashVer;
	},
	
	// Detects if the correct Flash Player plug-in version was installed
	isFlashVersionInstalled: function(major,minor,revision){
		//alert("isFlashVersionInstalled");
		var versionStr = this.getFlashVersion();
		if (versionStr == -1)
		{
			alert("No flash plugin installed");
			return false;
		}
		else
		{
			if(this.isIE && this.isWin && !this.isOpera)
			{
				// Given "WIN 2,0,0,11"
				tempArray		= versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
				tempString		= tempArray[1];				// "2,0,0,11"
				versionArray	= tempString.split(",");	// ['2', '0', '0', '11']
			}
			else
			{
				versionArray	= versionStr.split(".");
			}
			var versionMajor	= versionArray[0];
			var versionMinor	= versionArray[1];
			var versionRevision	= versionArray[2];

			if (versionMajor > parseFloat(major))
			{
				return true;
			}
			else if (versionMajor == parseFloat(major))
			{
				if (versionMinor > parseFloat(minor))
				{
					return true;
				}
				else if (versionMinor == parseFloat(minor))
				{
					if (versionRevision >= parseFloat(revision))
					{
						return true;
					}
				}
			}
			return false;
		}	
	}
}