/*
	unFocusFlashPlayerInfo, version 1.1 b3 (beta) (2006/03/14)
	Copyright: 2006, Kevin Newman (http://www.unfocus.com/)
	License: http://creativecommons.org/licenses/LGPL/2.1/
*/
if (typeof unFocus == "undefined") var unFocus = {};
if (!unFocus.Flash) unFocus.Flash = {};

if (!unFocus.Flash.Player) new function() {
	unFocus.Flash.Player = this;
	
	// private vars
	var _installed = false,
		_beta = false,
		_version = 0,
		_majorRevision = 0,
		_minorRevision = 0,
		_betaVersion = 0,
		_versionRaw = "",
		_pluginType = "",
		_releaseCode = "",
		_this=this;
	
	// detection work
	if (navigator.plugins && navigator.plugins.length > 0) {
		_versionRaw = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		if (_versionRaw) {
			_installed = true;
			_playerType = 'PlugIn';
			if (/Shockwave Flash/.test(_versionRaw)) {
				_version = _versionRaw.match(/Shockwave Flash (\d)\.(\d)/);
				_majorRevision = _version[2];
				if (/r\d+/.test(_versionRaw)) {
					_releaseCode = 'r';
					_minorRevision = _versionRaw.match(/r(\d+)/)[1];
				}
				_version = _version[1];
				if (/[abd]\d+/.test(_versionRaw)) { // I'm not sure what other letters would be here, but I've encountered b, d and a (alpha) so far
					_betaVersion = _versionRaw.match(/([abd])(\d+)/);
					_releaseCode = _betaVersion[1];
					_beta = true;
					_betaVersion = _betaVersion[2];
				}
			} else _version = 1;
		}
	} else if (window.ActiveXObject) {
		// src: Player.vbs
		document.write('<scr'+'ipt type="text/vbscript"\>\nFunction unFocusDetectActiveX(C)\n',
			"On Error Resume Next\nunFocusDetectActiveX=IsObject(CreateObject(C))\n",
			"End Function\nFunction unFocusDetectFlashVersion()\nOn Error Resume Next\n",
			'Set C=CreateObject("ShockwaveFlash.ShockwaveFlash.4")\n',
			'unFocusDetectFlashVersion=C.GetVariable("$',
			'version")\nEnd Function\n</scr'+'ipt\>');
		/*function _getActiveXObject($objectString) {
			try{
				var _control = new ActiveXObject($objectString);
				return _control;
			} catch (e){
				return false;
			}
		}
		function _getPlayerVersionDetails() {
			var $control = _getActiveXObject("ShockwaveFlash.ShockwaveFlash.4");
			$control.GetVariable("$"+"version");
		}*/
		var _versionTemp;
		
		function _parseVersion(_versionTemp) {
			_versionRaw = _versionTemp;
			_versionTemp = _versionTemp.split(',');
			_version = _versionTemp[0].match(/\d+/);
			_majorRevision = _versionTemp[1];
			_minorRevision = _versionTemp[2];
			_betaVersion = _versionTemp[3];
			if (_versionTemp[3]) _beta = true;
			// if the last number is 0, assume this is a release version
			else _releaseCode = 'r';
		}
		
		// we have to detect around Flash 6, since it can crash some versions of IE
		if (unFocusDetectActiveX("ShockwaveFlash.ShockwaveFlash.7"))
			_parseVersion(unFocusDetectFlashVersion());
		else if (unFocusDetectActiveX("ShockwaveFlash.ShockwaveFlash.6")) {
			// tread lightly
			_version = 6;
			_minorRevision = -1; // cannot be safely detected
		} else if (unFocusDetectActiveX("ShockwaveFlash.ShockwaveFlash.5"))
			_parseVersion(unFocusDetectFlashVersion());
		else if (unFocusDetectActiveX("ShockwaveFlash.ShockwaveFlash.4"))
			_version = 4;
		else if (unFocusDetectActiveX("ShockwaveFlash.ShockwaveFlash.3"))
			_version = 3;
		else if (unFocusDetectActiveX("ShockwaveFlash.ShockwaveFlash"))
			// Tested on Windows 95 with flash player 2 - using the ".2" at the end doesn't work, but this does ;-)
			// :BUG: This doesn't seem to work when FP2 is installed in WinXP
			_version = 2;
		if (_version) {
			_installed = true;
			_playerType = "ActiveX";
		}
	} else if (/WebTV/.test(navigator.userAgent)) { // WebTV
		_playerType = "WebTV";
		_versionRaw = navigator.userAgent.match(/WebTV\/(\d\.\d)/)[1];
		if (_versionRaw > 2.5) _version = 4;
		else if (_versionRaw == 2.5) _version = 3;
		else _version = 2;
	}
	
	// public/priveleged Getters
	_this.isInstalled = function() {
		return _installed;
	};
	_this.isBeta = function() {
		return _beta;
	};
	_this.getVersion = function() {
		return _version;
	};
	_this.getMajorRevision = function() {
		return _majorRevision;
	};
	_this.getMinorRevision = function() {
		return _minorRevision;
	};
	_this.getBetaVersion = function() {
		return _betaVersion;
	};
	_this.getVersionRaw = function() {
		return _versionRaw;
	};
	_this.getPluginType = function() {
		return _pluginType;
	};
	_this.getReleaseCode = function() {
		return _releaseCode;
	};
};
