/**
 * FileName:uaSwfObj.js
 * @author uniteair.co.jp
 */

/**********************************************************
* flash
*/

var FLASH_MAJOR_VERSION = 9;
var FLASH_MINOR_VERSION = 0;
var FLASH_REVISION      = 45;
var DEFAULT_FLASH_DIRECTORY = "/ap-common/swf/";
var PLAYER_PRODUCTION_INSTALLER_DIR = "/ap-common/swf/";
var PLAYER_PRODUCTION_INSTALLER_FILE = "playerProductInstall.swf";
var isU6r65 = true;
/**
 *  
 */
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;
		DEFAULT_NOFLASH_HTML = (props.noflash)?props.noflash:DEFAULT_NOFLASH_HTML;

		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 ) {
			if(isU6r65){
				html = this.displayInstaller(props);
			}else{
				html = this.displayAlternateContent();
			}
		} else if (hasReqestedVersion) {
			html = this.displayContent(props);
		} else {
			html = this.displayAlternateContent();
		}
		document.write(html);
	},
	displayContent:function(props){
		return this.getObjectTags(props);
	},
	displayInstaller:function(props){
		return DEFAULT_NOFLASH_HTML;
		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 flashVers = (props.flashVers)?props.flashVers:"";
		var wmode	= (props.wmode)?props.wmode:"window";
		var fname	= (props.fname)?props.fname:"flashName";
		var queriesStr	= (props.queries)?this.queryObjToStr(props.queries):"";
		var flashvars 		= (props.flashvars)?props.flashvars:"";
		var allowScriptAccess 		= (props.allowScriptAccess)?props.allowScriptAccess:"sameDomain";

		var htmlStr = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" id="'+fname+'">';
		htmlStr += '<param name="movie" value="'+dir+src+queriesStr+flashVers+'">';
		htmlStr += '<param name="quality" value="high">';
		htmlStr += '<param name="bgcolor" value="'+bgcolor+'">';
		htmlStr += '<param name="wmode" value="'+wmode+'">';
		htmlStr += '<param name="flashvars" value="'+flashvars+'">';
		htmlStr += '<param name="allowScriptAccess" value="'+allowScriptAccess+'">';
		if(queriesStr.indexOf("MMplayerTypeEmbed")>-1){ queriesStr = queriesStr.split("ActiveX").join("PlugIn"); }
		htmlStr += '<embed src="'+dir+src+queriesStr+flashVers+'" quality="high" wmode="'+wmode+'" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" flashvars="'+flashvars+'" name="'+fname+'" aligh="middle" play="true" loop="false" quality="high" allowScriptAccess="'+allowScriptAccess+'" type="application/x-shockwave-flash">';
		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 {
					// begin:modified 0902
					if(versionMajor>=7){
						isU6r65 = true;
					}else if(versionMajor==6){
						if(versionMinor>=1){
							isU6r65 = true;
						}else if(versionRevision>=65){
							isU6r65 = true;
						}else{
							isU6r65 = false;
						}
					}else{
						isU6r65 = false;
					}
					// end:modified 0902
					return (versionMajor > reqMajorVer);
				}
				//
			}
		}
	}
}
var uaSwfObj = new UaSwfObj();



