//<![CDATA[
var byPassFlash = false;
//instansiate object with given vars
FlashObject = function(fileName, id, width, height, versionRequired, bgColor, useExpressInstall, quality, detectKey){
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	this.useExpressInstall = useExpressInstall;
	this.doPopupConfirm = false;
	if(fileName) this.attributes['swf'] = fileName;
	if(id) this.attributes['id'] = id;
	if(width) this.attributes['width'] = width;
	if(height) this.attributes['height'] = height;
	if(versionRequired) this.attributes['version'] = new playerVersion(versionRequired.toString().split("."));
	this.installedVer = getPlayerVersion(this.attributes['version'], useExpressInstall);
	if(bgColor) this.params['bgcolor'] = bgColor;
	var quality = quality ? quality : 'high';
	this.params['quality'] = quality;

	this.getVariablePairs = function(){
		var variablePairs = new Array();
		var key;
		var variables = this.variables;
		for(key in variables){
		variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	}

	this.getFlashHTML = function() {
		var flashNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.attributes["doExpressInstall"]) this.variables['MMplayerType'] = "PlugIn";
			flashNode = '<embed type="application/x-shockwave-flash" src="'+ this.attributes['swf'] +'" width="'+ this.attributes['width'] +'" height="'+ this.attributes['height'] +'"';
			flashNode += ' id="'+ this.attributes['id'] +'" name="'+ this.attributes['id'] +'" ';
			var params = this.params;
			for(var key in params){ flashNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			if (pairs.length > 0){ flashNode += 'flashvars="'+ pairs +'"'; }
			flashNode += '/>';
		} 
		else { // PC IE
			if (this.attributes['doExpressInstall']) this.variables['MMplayerType'] = "ActiveX";
			var test;
			test = "document.write('<object id=main classid=clsid:D27CDB6E-AE6D-11cf-96BB-444553540000 width=900 height=558>');";
			test += "document.write('<param name=movie value=/flash/container.swf />');";
			test += "document.write('</object>');"
			flashNode = '<object id="'+ this.attributes['id'] +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.attributes['width'] +'" height="'+ this.attributes['height'] +'">';
			flashNode += '<param name="movie" value="'+ this.attributes['swf'] +'" />';
			var params = this.params;
			for(var key in params) {
				flashNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) flashNode += '<param name="flashvars" value="'+ pairs +'" />';
			flashNode += "</object>";
		}
		
		return flashNode;
	}
	
	this.writeHTML = function(elementId){
		if(this.useExpressInstall) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new playerVersion([6,0,65]);
			if (this.installedVer.isValidVersion(expressInstallReqVer) && !this.installedVer.isValidVersion(this.attributes['version'])) {
				this.attributes['doExpressInstall'] = true;
			}
		} 
		else {
			this.attributes['doExpressInstall'] = false;
		}
		if(byPassFlash || this.attributes['doExpressInstall'] || this.installedVer.isValidVersion(this.attributes['version'])) {
			var contentElement = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			contentElement.innerHTML = this.getFlashHTML();
		}
		else if(!this.installedVer.isValidVersion(this.attributes['version'])){
			this.doPopupConfirm = true;
		}
	}
}

function getPlayerVersion(reqVer, useExpressInstall) {
	var PlayerVersion = new playerVersion(0,0,0);
	if(navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new playerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}
	else {
		try {
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				PlayerVersion = new playerVersion([i,0,0]);
			}
		}
		catch(e) {
		}
		if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion;
		if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || useExpressInstall) {
			try{
				PlayerVersion = new playerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}
			catch(e) {
			}
		}
	}
	return PlayerVersion;
}
playerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) || 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
playerVersion.prototype.isValidVersion = function(version){
	if(this.major < version.major) return false;
	if(this.major > version.major) return true;
	if(this.minor < version.minor) return false;
	if(this.minor > version.minor) return true;
	if(this.rev < version.rev) return false;
	return true;
}

///
///Set the global byPass var to true and instansiate a ner flashObject
///
function byPassDetection() {
	byPassFlash = true;
	var flashObject = new FlashObject("/flash/container.swf", "main", "900", "558");
	flashObject.variables["localTest"] = "false";
	flashObject.variables["startPage"] = "home";
	flashObject.variables["whichSlate"] = "5";
	flashObject.writeHTML("PageContent");
}

function RunFoo()
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96BB-444553540000" width="900" height="558">\n');
	document.write('<param name="movie" value="/flash/container.swf" />\n');
	document.write('<embed src="/flash/container.swf" quality="high" bgcolor="#000000" width="900" height="558" name="foo" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />')
	document.write('</object>\n');
}
//]]>

