/*
	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\>');
		_versionRaw = unFocusDetectFlashVersion();
		/*try{
			var _control = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.4");
			_control.GetVariable("$"+"version");
		} catch (e){}*/
		if (_versionRaw) {
			_versionRaw = _versionRaw.split(',');
			_version = _versionRaw[0].match(/\d+/);
			_majorRevision = _versionRaw[1];
			_minorRevision = _versionRaw[2];
			_betaVersion = _versionRaw[3];
			if (_versionRaw[3]) _beta = true;
			// if the last number is 0, assume this is a release version
			else _releaseCode = 'r';
		} 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 ;-)
			_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;
	};
};
