/*******************************************************
FLASH DETECT 2.5
All code by Ryan Parman and mjac, unless otherwise noted.
(c) 1997-2004 Ryan Parman and mjac
>>  KPK ModemMedia:  This is a usefully tiny, modern script.
http://www.skyzyx.com
*******************************************************/

// This script will test up to the following version.
flash_versions = 20;

// This is used in the flash write
var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;

// Initialize variables and arrays
var flash = new Object();
flash.installed=false;
flash.version='0.0';

// Dig through Netscape-compatible plug-ins first.
if (navigator.plugins && navigator.plugins.length) {
	for (x=0; x < navigator.plugins.length; x++) {
		if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
			flash.version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
			flash.installed = true;
			break;
		}
	}
}

// Then, dig through ActiveX-style plug-ins afterwords
else if (window.ActiveXObject) {
	for (x = 2; x <= flash_versions; x++) {
		try {
			oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
			if(oFlash) {
				flash.installed = true;
				flash.version = x + '.0';
			}
		}
		catch(e) {}
	}
}

// Create sniffing variables in the following style: flash.ver[x]
// Modified by mjac
flash.ver = Array();
for(i = 4; i <= flash_versions; i++) {
	eval("flash.ver[" + i + "] = (flash.installed && parseInt(flash.version) >= " + i + ") ? true : false;");
}

////////////////////////////////////////////////////////////////////
// Start of larger Macromedia Detector.  Required for auto-upgrades

// Location visited after installation is complete if installation is required
var MMredirectURL = location.href;

var jsVersion = 1.1;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	if (isIE && isWin && !isOpera) {
		if (window.ActiveXObject) {
			try {
				oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');");
				if(oFlash) return oFlash.getVariable("$version"); else flashVer = -1;
			}
			catch(e) {flashVer = -1;}
		} else flashVer = -1;
	} else if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		} else {
			flashVer = -1;
		}
	} else {
		flashVer = -1;
	}
	return flashVer;
}
// If called with no parameters this function returns a floating point value
// which should be the version of the Flash Player or 0.0
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	// loop backwards through the versions until we find the newest version
	for (i=25;i>0;i--) {
		versionStr = JSGetSwfVer(i);
		if (versionStr == -1 ) {
			continue;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];

			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
			// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}
	return (reqVer ? false : 0.0);
}


var hasProductInstall = DetectFlashVer(6, 0, 65);
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

var flashRejected = false;

if (document.cookie.match("flashrejected") != null ) {
    flashRejected = true;		
} 

function displayFlash(url,width,height) {
	//Eolas workaround

	if ( !hasReqestedVersion && hasProductInstall ) {
		document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		var MMdoctitle = document.title;
		return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+ 'width="'+width+'" height="'+height+'"  loop="false"'
			+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
			+ '<param name="movie" value="/content_data/GME/019/common/v2/playerProductInstall.swf?MMredirectURL='+MMredirectURL.replace("&","%26")+'&MMplayerType=ActiveX&MMdoctitle='+MMdoctitle+'" />'
			+ '<param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="loop" value="false" />'
			+ '<embed src="/content_data/GME/019/common/v2/playerProductInstall.swf?MMredirectURL='+MMredirectURL.replace("&","%26")+'&MMplayerType=PlugIn" quality="high" bgcolor="#000000" '
			+ 'width="'+width+'" height="'+height+'" name="detectiontest" aligh="middle"'
			+ 'play="true" wmode="transparent"'
			+ 'loop="false"'
			+ 'quality="high"'
			+ 'allowScriptAccess="sameDomain"'
			+ 'type="application/x-shockwave-flash"'
			+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
			+ '<\/embed>'
			+ '<\/object>';
	} else if (hasReqestedVersion) {  // if we've detected an acceptable version
		var out = '';
		out += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" align="middle">';
		out += '<param name="allowScriptAccess" value="sameDomain" />';
		var flashPath = url;
		if (flashPath.match(/\?/)) flashPath = flashPath.substr(0,flashPath.lastIndexOf('?'));
		flashPath = flashPath.substr(0,flashPath.lastIndexOf('/'));
		out += '<param name="movie" value="'+url+'?path='+flashPath+'" />';
		out += '<param name="quality" value="high" /><param name="loop" value="false" />';
		// out += '<param name="scale" value="noscale" />';
		out += '<param name="wmode" value="transparent" />';
		out += '<embed src="'+url+'?path='+flashPath+'" loop="false" quality="high" wmode="transparent" width="'+width+'" height="'+height+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		out += '</object>';
		return out;
	} else {
		return "";
	}
}
function cancelFlashUpgrade() {
	document.cookie = "flashrejected=true";
	location.reload();
}
function writeFlash(flashStr) {
	document.write(flashStr);
}
