/*
nhn japan uxdc uit
2009-02-18
ver 2.60
*/
var SwfPutter = $Class({
	$init : function(){
		this.vars = null;
		this.fElm = null;
		this.params = {
				allowScriptAccess:'always',
				swLiveConnect:'true',
				wmode:'transparent',
				quality:'high',
				loop:'false',
				menu:'false'
			};
		var options = this.opt = this._getOptions( arguments[0] );
		this.cFpVersion = new this._FPVersion(this.opt.fp.split("."));
		
		this.isIE = $Agent().navigator().ie;
		
		var url = location + '';
		this.protocol = url.match('^https?');
		(this.protocol)? this.protocol = this.protocol[0] : this.protocol = 'http'
	},
	_getOptions : function(param){
		var option = {
				fp:'9.0.0',
				id:''
			};
		if (typeof param == "undefined") param = new Object;
		for(var x in param) option[x] = param[x];
		return option;
	},
	put : function(elmID){
		var fpVersion;
		(this.opt.fp == 'any')?fpVersion = true : fpVersion = this._getFPVersion();

		if(elmID) this.fElm = $Element(elmID);

		if(!fpVersion){
			(this.fElm)? this.fElm.html(this._makeTag()): document.write(this._makeTag());
			return;
		}
		if(!this._fpValid(fpVersion) && !$Agent().navigator().ie) return;
		(this.fElm)? this.fElm.html(this._makeTag()): document.write(this._makeTag());
	},
	addVars : function(vars){this.vars = this._makeParam(vars);},
	addParam : function(param){for(var k in param) this.params[k] = param[k];},
	_makeTag : function(){
		if (this.isIE) {
			var fHTML = '<object id="' + this.opt.id + '" codebase="' + this.protocol + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.cFpVersion['major'] + ',' + this.cFpVersion['minor'] + ',' + this.cFpVersion['rev'] + ',0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" type="application/x-shockwave-flash" width="' + this.opt.w + '" height="' + this.opt.h + '">';
			fHTML += '<param name="movie" value="' + this.opt.src + '" />';
			for (var k in this.params) 
				fHTML += '<param name="' + k + '" value="' + this.params[k] + '" />';
			if (this.vars) 
				fHTML += '<param name="FlashVars" value="' + this.vars + '" />';
			fHTML += "</object>";
		}else {
			var fHTML = '<embed type="application/x-shockwave-flash" pluginspage="' + this.protocol + '://www.adobe.com/go/getflashplayer" src="' + this.opt.src + '" id="' + this.opt.id + '" name="' + this.opt.id + '" width="' + this.opt.w + '" height="' + this.opt.h + '" ';
			for (var k in this.params) fHTML += k + '="' + this.params[k] + '" ';
			if (this.vars)fHTML += 'FlashVars="' + this.vars + '" ';
			fHTML += '/>';
		}
		return fHTML;
	},
	_makeParam : function(obj){
		var paramAry = new Array();
		for(var k in obj) paramAry.push(k+'='+obj[k]);
		return paramAry.join('&');
	},
	_FPVersion : function(verAry){
		this.major = (verAry[0])? parseInt(verAry[0]) : 0;
		this.minor = (verAry[1])? parseInt(verAry[1]) : 0;
		this.rev = (verAry[2])? parseInt(verAry[2]) : 1;
	},
	_fpValid : function(fpVersion){
		if(fpVersion['major'] < this.cFpVersion['major']){this._errorAlert(fpVersion);return false;}
		if(fpVersion['major'] > this.cFpVersion['major']) return true;
		if(fpVersion['minor'] < this.cFpVersion['minor']){this._errorAlert(fpVersion);return false;}
		if(fpVersion['minor'] > this.cFpVersion['minor']) return true;
		if(fpVersion['rev'] < this.cFpVersion['rev']){this._errorAlert(fpVersion);return false;}
		if(fpVersion['rev'] > this.cFpVersion['rev']) return true;
		return true;
	},
	_errorAlert : function(fpVersion){
		var installedFpVerStr = fpVersion['major'] + '.' + fpVersion['minor'] + '.' + fpVersion['rev'];
		alert('現在インストールされているFlash Playerのバージョンは'+installedFpVerStr+'ですが、このコンテンツのご利用には、' + this.opt.fp +'以上のバージョンが必要です');	
	},
	_getFPVersion : function(){
		var FPVersion = new this._FPVersion([0,0,0]);
		
		if(navigator.plugins && navigator.mimeTypes.length){
			var fp = navigator.plugins["Shockwave Flash"];
			if(!fp) return null;
			if(fp.description) {
				FPVersion = new this._FPVersion(fp.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
				return FPVersion;
			}
		}else if(window.ActiveXObject){ 
			try{
				// 7 and later
				return this._makeIEVer(new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"));
			}catch(e){}
		
			try {
				// 6
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				FPVersion = new this._FPVersion([6,0,21]);
				axo.AllowScriptAccess = "always";
				return this._makeIEVer(axo);
			}catch(e){}
	
			try {
				// 5 4
				return this._makeIEVer(new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"));
			}catch(e){}
			
			try {
				// 3
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				return new this._FPVersion([3,0,18]);
			}catch(e){}
		}
		return null;
	},
	_makeIEVer : function(axo){
		return new this._FPVersion(axo.GetVariable("$version").split(" ")[1].split(","));
	}
});