
var flash = function() {

	var UNDEF = "undefined",
		OBJECT = "object",
		SHOCKWAVE_FLASH = "Shockwave Flash",
		SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
		FLASH_MIME_TYPE = "application/x-shockwave-flash",
		EXPRESS_INSTALL_ID = "SWFObjectExprInst",

		win = window,
		doc = document,
		nav = navigator,
	
		domLoadFnArr = [],
		regObjArr = [],
		objIdArr = [],
		listenersArr = [],
		script,
		timer = null,
		storedAltContent = null,
		storedAltContentId = null,
		isDomLoaded = false,
		noflash = true,
		isExpressInstallActive = false;
	
	var w3cdom = typeof doc.getElementById != UNDEF && typeof doc.getElementsByTagName != UNDEF && typeof doc.createElement != UNDEF,
	playerVersion = [0,0,0],
	d = null;
	
	if(
		typeof nav.plugins != UNDEF && 
		typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT
	){
		d = nav.plugins[SHOCKWAVE_FLASH].description;
		if(
			d && 
			!(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)
		){ 
			// navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
			d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
			playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
			playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
			playerVersion[2] = /r/.test(d) ? parseInt(d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
		}
	}
	else if (typeof win.ActiveXObject != UNDEF){
	
		var a = null, fp6Crash = false;
		try {
			a = new ActiveXObject(SHOCKWAVE_FLASH_AX + ".7");
		}
		catch(e) {
			try { 
				a = new ActiveXObject(SHOCKWAVE_FLASH_AX + ".6");
				playerVersion = [6,0,21];
				a.AllowScriptAccess = "always";	 // Introduced in fp6.0.47
			}
			catch(e) {
				if (playerVersion[0] == 6) {
					fp6Crash = true;
				}
			}
			if (!fp6Crash) {
				try {
					a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
				}
				catch(e) {}
			}
		}
			if (!fp6Crash && a) { // a will return null when ActiveX is disabled
			try {
				d = a.GetVariable("$version");	// Will crash fp6.0.21/23/29
				if (d) {
					d = d.split(" ")[1].split(",");
					playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
				}
			}
			catch(e) {}
		}
	}

	var u = nav.userAgent.toLowerCase(),
	p = nav.platform.toLowerCase(),
	webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, // returns either the webkit version or false if not webkit
	ie = false,
	windows = p ? /win/.test(p) : /win/.test(u),
	mac = p ? /mac/.test(p) : /mac/.test(u);

	if(playerVersion[0] > 0 || playerVersion[1] > 0 || playerVersion[2] > 0){
		noflash = false;
	}

	return {
		NOFLASH:noflash, // true or false
		W3CDOM:w3cdom, // true or false
		VERSION:playerVersion, // player version or 0,0,0
		WEBKIT:webkit, // webkit version or false
		IE:ie, // true or false
		WINDOWS:windows, // true or false
		MAC:mac // true or false
	};
	
}();



function flashVersion(reqVersionStr){
	
	var versionInstalled = false;
	var units = reqVersionStr.split('.');
	var flashInfo = flash;

	// check player version 
	if(!flashInfo.NOFLASH && flashInfo.VERSION){
		var units = reqVersionStr.split('.');
		if(flashInfo.VERSION[0] > parseInt(units[0])){
			versionInstalled = true;
		}else if(flashInfo.VERSION[0] == parseInt(units[0])){
			if(flashInfo.VERSION[1] > parseInt(units[1])){
				versionInstalled = true;	
			}else if(flashInfo.VERSION[1] == parseInt(units[1])){
				if(flashInfo.VERSION[2] >= parseInt(units[2])){
					versionInstalled = true;
				}
			}
		}
	}
	
	return {
		NOFLASH:flashInfo.NOFLASH, // true or false
		REQUIRED:versionInstalled , // true or false
		VERSION:flashInfo.VERSION[0]+'.'+flashInfo.VERSION[1]+'.'+flashInfo.VERSION[2] // string with the player version
	};
}

