//flash文件

(function(W){
	
	var Flash=(function(W){
		var Flash=function(id){
			return new Flash.fn.init(id);
		},
		D=W.document;
		Flash.fn = Flash.prototype ={
			init:function(id){
				//this.alert(id);
				this.isIE=/(msie) ([\w.]+)/i.test(navigator.userAgent);
				this.getFlash();
				if(!id)return this;
				return this.getByID(id);
				//return this.getByID(id);
			},
			isIE:false,
			getByID:function(id){
				if(!this.isFlash)return false;
				if(this.isIE){
					return document.getElementById(id);
				}else{
					return D[id];
				}
			},
			write:function(o){
				D.write(this.get(o));
			},
			get:function(o){
				if(!this.isFlash||this.version<10){
					return "你需要升级FLASH播放器版本至10.0+,请下载";
				}
				var str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" #size# >#param#<embed pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" menu="false" #para# ></embed></object>';
				if(o.constructor!=Object)return '';
				o=this.extend(o);
				var size="";
				var param="";
				var para="";
				for(var a in o){
					if(a=='id'){
						size+=' id="'+o[a]+'" ';
						para+=' name="'+o[a]+'" ';
					}else if(a=='width'||a=="height"){
						size+=' '+a+'="'+o[a]+'" ';
						para+=' '+a+'="'+o[a]+'" ';
					}else if(a=='src'){
						param+='<param name="movie" value="'+o[a]+'" />';
						para+=' src="'+o[a]+'" ';
					}else{
						param+='<param name="'+a+'" value="'+o[a]+'" />';
						para+=' '+a+'="'+o[a]+'" ';
					}
				}
				str=str.replace(/#size#/g,size);
				str=str.replace(/#param#/g,param);
				str=str.replace(/#para#/g,para);
				
				return str;
			},
			def:function(){
				return {
					src:'',
					width:100,
					height:100,
					id:"flash",
					allowscriptaccess:"always",
					wmode:"transparent",
					quality:"high",
					menu:"false",
					flashvars:""
				};
			},
			extend:function(o){
				var e=this.def();
				if(o.constructor==String){
					e.src=o;
				    return e;
				}
				if(o.constructor!=Object)return '';	
				for(var a in o){
					e[a.toLowerCase()]=o[a];
				}
				return e;
			},
			version:0,
			isFlash:false,
			getFlash:function(){
			 if(this.isIE){
				var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
					if(swf) {
						this.isFlash=true;
						var vswf=swf.GetVariable("$version");
						this.version=parseInt(vswf.split(" ")[1].split(",")[0]);
					}
			  }else{
					if (navigator.plugins && navigator.plugins.length > 0){
					var swf=navigator.plugins["Shockwave Flash"];
						if (swf){
							this.isFlash=true;
							var words = swf.description.split(" ");
							for (var i = 0; i < words.length; ++i){
								if (isNaN(parseInt(words[i]))) continue;
								this.version = parseInt(words[i]);
							 }
						 }
					}
				}
			}
		};
		Flash.fn.init.prototype=Flash.fn;
		W.flash=Flash();
		return (W.Flash=Flash);
	})(W);
	
}(window));
