// Flash Version Detector  v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)


var flashVersion_DONTKNOW = -1;
var flashVersion = null;

function getFlashVersion()
{
	if (flashVersion == null)
	{
		flashVersion = detectFlashVersion();
	}
	
	return flashVersion;
}

function detectFlashVersion()
{
	var agent = navigator.userAgent.toLowerCase();
	var tmpVer = flashVersion_DONTKNOW;
	
	try
	{
		// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
		if (typeof(navigator.plugins) == 'object' && navigator.plugins.length > 0)
		{
			var flashPlugin = navigator.plugins['Shockwave Flash'];
			if (typeof(flashPlugin) == 'object')
			{
				tmpVer = flashVersion_DONTKNOW;
				
				//description is something like "Shockwave Flash 9.0 r16"
				var tmpStr = flashPlugin.description;
				var tmpArr = tmpStr.split(" ");
				tmpVer = parseInt(tmpArr[2]);
			}
		}
	
		// IE4+ Win32:  attempt to create an ActiveX object using VBScript
		else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 
			&& agent.indexOf("win") != -1 && agent.indexOf("16bit") == -1)
		{
				//throws exception if it fails
				var tmpObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				
				//there is some flash installed, because no exception yet
				tmpVer = flashVersion_DONTKNOW;
				
				//version is something like "WIN 9,0,1,2"
				var tmpStr = tmpObj.GetVariable("$version");
				var tmpArr = tmpStr.split(" ");
				tmpVer = parseInt(tmpArr[1]);
		}
			
		// WebTV 2.5 supports flash 3
		else if (agent.indexOf("webtv/2.5") != -1)
		{
			tmpVer = 3;
		}
	
		// older WebTV supports flash 2
		else if (agent.indexOf("webtv") != -1)
		{
			tmpVer = 2;
		}
	}
	catch (e)
	{
		//ignore
	}	

	return tmpVer;
}
