var S3FlashUpload=new Class({Implements:[Options,Events],options:{form:null,progress:null,file:null,fakeFile:null,browse:null,s3BucketUri:null,s3Form:null,s3ContentType:null,s3FilePrefix:null,name:"flashUpload",fieldName:"fileName",maxUploadSize:67108864,path:"swiff.uploader.swf",messageMaxUploadSize:"Please upload only files smaller than {maxUploadSize}.",messageUploadFailed:'Upload "{file}" failed.',onSubmit:Class.empty,onUpload:Class.empty,onSelect:Class.empty,onSelectError:Class.empty,onError:Class.empty,onComplete:Class.empty,debug:false},initialize:function(A){this.setOptions(A);if(!A.onSelectError){this.addEvent("onSelectError",this.onSelectError)}if(!A.onError){this.addEvent("onError",this.onError)}this.form=$(this.options.form);this.progress=$(this.options.progress);this.file=$(this.options.file);this.fakeFile=$(this.options.fakeFile);this.browse=$(this.options.browse);this.s3Form=$(this.options.s3Form);this.s3ContentType=$(this.options.s3ContentType);this.maxUploadSizeKB=this.sizeToKB(this.options.maxUploadSize);if(this.form&&this.progress&&this.file&&this.fakeFile&&this.browse&&this.s3Form&&this.s3ContentType){if(Browser.Plugins.Flash.version>=9&&!(Browser.Engine.webkit419||Browser.Engine.presto925)){this.swiffy=new Uploader(this.progress,{url:this.s3Form.getProperty("action"),id:this.options.name+"Swiffy",fieldName:"file",limitSize:this.options.maxUploadSize,path:this.options.path,target:this.browse,debug:this.options.debug,onLoad:function(){var B=this.file.getProperty("id");this.file.destroy();this.file=new Element("input",{type:"hidden",name:this.options.fieldName,value:""}).inject(this.fakeFile,"before");this.fakeFile.setProperty("id",B);this.fakeFile.removeClass("hidden");this.browse.removeClass("hidden")}.bind(this),onSelect:function(B){if(B.size>this.options.maxUploadSize||B.size==0){this.fireEvent("onSelectError",B);return false}else{var C=B.name.trim();this.fakeFile.value=C;this.s3ContentType.value=MIMEtype.getType(C);this.fireEvent("onSelect",B);return true}}.bind(this),fileError:function(C,B,D){this.progress.addClass("hidden");this.file.value="";this.fakeFile.value="";this.fireEvent("onError",[C,B,D])}.bind(this),fileUpload:function(C,B){this.progress.removeClass("hidden");this.fireEvent("onUpload",C)}.bind(this),fileComplete:function(C,B){this.file.value=this.options.s3BucketUri+encodeURIComponent(this.options.s3FilePrefix+C.name.trim());this.fireEvent("onComplete",{file:C,response:B});this.form.submit()}.bind(this)});this.browse.addEvent("click",function(B){B.stop();this.swiffy.browse()}.bind(this))}else{this.swiffy=null}}},delaySubmit:function(){this.form.submit()},submit:function(){if(this.swiffy&&this.swiffy.files.length){this.file.value="";this.swiffy.upload({data:this.s3Form})}else{this.fireEvent("onSubmit");this.delaySubmit.delay(100,this)}},reposition:function(){if(this.swiffy){this.swiffy.reposition()}},sizeToKB:function(A){var B="B";if((A/1048576)>1){B="MB";A/=1048576}else{if((A/1024)>1){B="kB";A/=1024}}return A.round(1)+" "+B},onSelectError:function(A){var B={maxUploadSize:this.maxUploadSizeKB};alert(this.options.messageMaxUploadSize.substitute(B))},onError:function(B,A,D){var C={file:B.name.trim()};alert(this.options.messageUploadFailed.substitute(C))}});