var FLASH_MAJOR_VERSION = 8;
var FLASH_MINOR_VERSION = 0;
var FLASH_REVISION      = 0;
var DEFAULT_FLASH_DIRECTORY = "";
var PLAYER_PRODUCTION_INSTALLER_DIR = "/swf/";
var PLAYER_PRODUCTION_INSTALLER_FILE = "playerProductInstall.swf";
var DEFAULT_NOFLASH_HTML = '<img src="/img/no_flash.jpg" width="558" height="250" alt=""  usemap="#map">';

/**
 *  
 */
document.write('<script language="V'+'BScript" type="text/vbscript">');
document.write('Function VBGetSwfVer(i)\n');
document.write('  on error resume next\n');
document.write('  Dim swControl, swVersion\n');
document.write('  swVersion = 0\n');
document.write('  set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))\n');
document.write('  if (IsObject(swControl)) then\n');
document.write('    swVersion = swControl.GetVariable("$version")\n');
document.write('  end if\n');
document.write('  VBGetSwfVer = swVersion\n');
document.write('End Function\n');
document.write('</script>\n');
/**
 * 
 */
function UaSwfObj(){
	this.isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	this.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	this.isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	this.checkerVersion = {major:6, minor:0, revision:0};
}
UaSwfObj.prototype = {
	display:function(props){
		var majorVersion 	= (props.majorVersion)?props.majorVersion:FLASH_MAJOR_VERSION;
		var minorVersion 	= (props.minorVersion)?props.minorVersion:FLASH_MINOR_VERSION;
		var revision 			= (props.revision)?props.revision:FLASH_REVISION;

		var hasProductInstall = this.detect(this.checkerVersion.major, this.checkerVersion.minor, this.checkerVersion.revision);
		var hasReqestedVersion = this.detect(majorVersion, minorVersion, revision);

		var html = "";
		if ( hasProductInstall && !hasReqestedVersion ) {
			html = this.displayInstaller(props);
		} else if (hasReqestedVersion) {
			html = this.displayContent(props);
		} else {
			html = this.displayAlternateContent();
		}
		document.write(html);
	},
	displayContent:function(props){
		return this.getObjectTags(props);
	},
	displayInstaller:function(props){
		var obj = new Object();
		obj.MMredirectURL = window.location;
		obj.MMplayerType  = "ActiveX";
		obj.MMdoctitle    = "MMdoctitle";
		props.queries = obj; 
		props.dir = PLAYER_PRODUCTION_INSTALLER_DIR;
		props.src = PLAYER_PRODUCTION_INSTALLER_FILE; 
		return this.getObjectTags(props);
	},
	displayAlternateContent:function(){
		return DEFAULT_NOFLASH_HTML;
	},
	getObjectTags:function(props){
		var src 		= (props.src)?props.src:"";
		var width 		= (props.width)?props.width:"";
		var height		= (props.height)?props.height:"";
		var dir 		= (props.dir)?props.dir:DEFAULT_FLASH_DIRECTORY;
		var bgcolor 	= (props.bgcolor)?props.bgcolor:"#ffffff";
		var align		= (props.align)?props.align:"";
		var scale		= (props.scale)?props.scale:"showall";
		var wmode		= (props.wmode)?props.wmode:"transparent";
		var devicefont	= (props.devicefont)?props.devicefont:"true";
		var id			= (props.id)?props.id:"";
		var allowFullScreen	= (props.allowFullScreen)?props.allowFullScreen:"false";
		var allowScriptAccess	= (props.allowScriptAccess)?props.allowScriptAccess:"sameDomain";
		var flashVers	= (props.flashVers)?props.flashVers:"";
		var queriesStr	= (props.queries)?this.queryObjToStr(props.queries):"";

		var htmlStr = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" id="'+id+'" align="middle">';
		htmlStr += '<param name="movie" value="'+dir+src+queriesStr+'">';
		htmlStr += '<param name="quality" value="high">';
		htmlStr += '<param name="bgcolor" value="'+bgcolor+'">';
		htmlStr += '<param name="scale" value="'+scale+'">';
		htmlStr += '<param name="wmode" value="'+wmode+'">';
		htmlStr += '<param name="devicefont" value="'+devicefont+'">';
		htmlStr += '<param name="allowFullScreen" value="'+allowFullScreen+'">';
		htmlStr += '<param name="allowScriptAccess" value="'+allowScriptAccess+'">';
		if(queriesStr.indexOf("MMplayerTypeEmbed")>-1){ queriesStr = queriesStr.split("ActiveX").join("PlugIn"); }
		htmlStr += '<embed src="'+dir+src+queriesStr+'" quality="high" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="flashcontent" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent">';
		htmlStr += '<\/embed>';
		htmlStr += '<\/object>';
		return htmlStr;
	},
	queryObjToStr:function(obj){
		if(!obj) return false;
		var queryArr = new Array();
		for(var tmp in obj){
			queryArr[queryArr.length] = tmp+"="+obj[tmp];
		}
		return (queryArr.length>0)?"?"+queryArr.join("&"):res;
	},
	GetSwfVer:function(){
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		var flashVer = -1;
		
		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;			
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}
		// 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;
		else if ( this.isIE && this.isWin && !this.isOpera ) {
			//flashVer = ControlVersion();
		}	
		return flashVer;
	},
	detect:function(reqMajorVer, reqMinorVer, reqRevision){
	 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	   	// loop backwards through the versions until we find the newest version	
		for (i=25;i>0;i--) {	
			if (this.isIE && this.isWin && !this.isOpera) {versionStr = VBGetSwfVer(i);}
			else {versionStr = this.GetSwfVer(i);}
			if (versionStr == -1 ) {
				return false;
			} else if (versionStr != 0) {
				if(this.isIE && this.isWin && !this.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;
				versionNum = parseFloat(versionString);
				//
				if(versionMajor == reqMajorVer) {
					if(versionMinor == reqMinorVer) {return (versionRevision >= reqRevision);}
					else{return (versionMinor > reqMinorVer);}
				}else {
					return (versionMajor > reqMajorVer);
				}
				//
			}
		}
	}
}
var uaSwfObj = new UaSwfObj();


