var rmaf_ie=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false;
var rmaf_win=(navigator.appVersion.toLowerCase().indexOf("win")!=-1)?true:false;
var rmaf_op=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;

function rmaSWFVersion(i){
	/*@cc_on
	@if (@_jscript_version >= 5)
	var sw;
	try{sw=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);}catch(e){try{sw=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){return -1;}}
	try{return sw.GetVariable("$version");}catch(e){return -1;}
	@else
	return -1;
	@end @*/
	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;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		flashVer = -1;
	}
	return flashVer;
}

function RMAFlashObject(w,h,mi,murl){
	this.width = w;
	this.height = h;
	this.movieId = mi;
	this.movieURL = murl;
	this.bgcolor = "#ffffff";
	this.minVer = "7,0,0,0";
	this.align = "middle";
	this.scriptAccess = "sameDomain";
	this.play = null;
	this.loop = null;
	this.quality = "high";
	this.wmode = null;
	this.scale = null;
	this.salign = null;
	this.deviceFont = null;
	this.menu = null;
	this.fv = null;
	this.useDetect=false;
	this.reqMajorVersion=6;
	this.reqMinorVersion=0;
	this.requiredRevision=0;
	this.alternateContent='';
	this.styling='';
}

new RMAFlashObject(0,0,0,0);

function rmaflash_detectRequired(reqMajorVer, reqMinorVer, reqRevision)
{
	if(!this.useDetect){return true;}
 	rqv=parseFloat(this.reqMajorVersion+"."+this.requiredRevision);
   	// loop backwards through the versions until we find the newest version
	for (i=25;i>0;i--) {
		vstr=rmaSWFVersion(i);
		if (vstr == -1 ){return false;}
		else if(vstr != 0){
			if(rmaf_ie&&rmaf_win&&!rmaf_op){tarr=vstr.split(" ");tstr=tarr[1];varr=tstr.split(",");}
			else{varr= vstr.split(".");}
			vmaj=varr[0];
			vmin=varr[1];
			vrev=varr[2];
            vnum=parseFloat(vmaj+"."+vrev);
			if((vmaj>this.reqMajorVersion)&&(vnum>=rqv)){return true;}
			else{return ((vnum >= rqv && vmin >= this.reqMinorVersion) ? true : false );}
		}
	}
	return(rqv?false:0.0);
}


function rmaflash_write(d){
	var _d=(d==null)?document:d;
	if(this.detectRequired()){
	var tw='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.minVer+'" width="'+this.width+'" height="'+this.height+'" id="'+this.movieId+'" align="'+this.align+' style="'+this.styling+'">';
	var ew='<embed src="'+this.movieURL+'" quality="'+this.quality+'" bgcolor="'+this.bgcolor+'" width="'+this.width+'" height="'+this.height+'" name="'+this.movieId+'" align="'+this.align+'" allowScriptAccess="'+this.scriptAccess+'" style='+this.styling+' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer "';
	tw=tw+'<param name="allowScriptAccess" value="'+this.scriptAccess+'" />';
	tw=tw+'<param name="movie" value="'+this.movieURL+'" />';
	tw=tw+'<param name="quality" value="'+this.quality+'" />';
	tw=tw+'<param name="bgcolor" value="'+this.bgcolor+'" />';
	if(this.play!=null){tw=tw+'<param name="play" value="'+this.play+'" />';ew=ew+' play="'+this.play+'"';}
	if(this.loop!=null){tw=tw+'<param name="loop" value="'+this.loop+'" />';;ew=ew+' loop="'+this.loop+'"';}
	if(this.menu!=null){tw=tw+'<param name="menu" value="'+this.menu+'" />';}
	if(this.scale!=null){tw=tw+'<param name="scale" value="'+this.scale+'" />';;ew=ew+' scale="'+this.scale+'"';}
	if(this.salign!=null){tw=tw+'<param name="salign" value="'+this.salign+'" />';ew=ew+' salign="'+this.salign+'"';}
	if(this.wmode!=null){tw=tw+'<param name="wmode" value="'+this.wmode+'" />';ew=ew+' wmode="'+this.wmode+'"';}
	if(this.deviceFont!=null){tw=tw+'<param name="devicefont" value="'+this.deviceFont+'" />';ew=ew+' devicefont="'+this.deviceFont+'"';}
	if(this.fv!=null){tw=tw+'<param name="FlashVars" value="'+this.fv+'"/>';ew=ew+' FlashVars="'+this.fv+'"';}
	ew=ew+"/>";
	tw=tw+ew+"</object>";
	_d.write(tw);
	}else{
		_d.write(this.alternateContent);
	}
}
function rmaflash_addVar(t,v){if(this.fv==null){this.fv=t+'='+escape(v);}else{this.fv=this.fv+'&'+t+'='+escape(v);}}

RMAFlashObject.prototype.write=rmaflash_write;
RMAFlashObject.prototype.addVar=rmaflash_addVar;
RMAFlashObject.prototype.detectRequired=rmaflash_detectRequired;

//Utility function so that movies can be dropped in as one liners.
function rmaCreateFlashControl(width,height,movieId,movieURL,backgroundColor,loopFlag,flashVars,playFlag,minver,alignment,scriptAccess,movieQuality,wmode,scale,salign,devicefont,menuFlag,styling){
	var f = new RMAFlashObject(width,height,movieId,movieURL);
	f.bgcolor=backgroundColor;
	f.loop=loopFlag;
	f.play=playFlag;
	f.minVer=minver;
	f.align=alignment;
	f.scriptAccess=scriptAccess;
	f.quality=movieQuality;
	f.wmode=wmode;
	f.scale=scale;
	f.salign=salign;
	f.deviceFont=devicefont;
	f.menu=menuFlag;
	f.styling=styling;
	if( flashVars!=null){
		for(var i=0;i<flashVars.length;i++){
			f.addVar(flashVars[i][0],flashVars[i][1]);
		}
	}
	f.write(document);
}
