window.addEvent("domready",function(){$("weaverbox-flash-version").appendText(Browser.Plugins.Flash.version);var jsonRequest=new Request.JSON({url:"files/fascade.php",onComplete:function(data){var maxUploadSize=(data.MAX_UPLOAD_SIZE).toInt();var maxPostSize=(data.MAX_POST_SIZE).toInt();var invalidFileExtensions=data.INVALID_FILE_EXT;var validFileExtensions=data.VALID_FILE_EXT;var highlightColor=data.HIGHLIGHT_COLOR;function mbToBytes(mb){return mb*1024*1024}function getFileExtension(filename){if(!filename){return""}if(filename.length==0){return""}var dot=filename.lastIndexOf(".");if(dot==-1){return""}var extension=filename.substr(dot,filename.length);return extension}function isValidExtension(ext){return(!invalidFileExtensions.contains(ext.toLowerCase())||validFileExtensions.contains(ext.toLowerCase()))}function isValidFileSize(size){if(!size){return false}if(size<mbToBytes(minSize())){return true}}function minSize(){return(maxUploadSize<maxPostSize?maxUploadSize:maxPostSize)}function totalFileSize(files){var size=0;for(i=0;i<files.length;i++){size+=files[i].size}return size}function trimName(name){if(name.length>24){first=name.slice(0,6);last=name.slice(name.length-6);name=first+"..."+last}return name}function resetUI(obj){obj.overallTitle.set("html","Overall Progress");obj.currentTitle.set("html","File Progress");obj.currentText.set("html","");obj.overallProgress.set(0);obj.currentProgress.set(0)}$("weaverbox-max_upload_size").appendText(minSize()+"MB");$("weaverbox-restricted-file-type").appendText(invalidFileExtensions.join(", "));var swiffy=new FancyUpload2($("weaverbox-status"),$("weaverbox-list"),{url:$("form-weaverbox").action,limitFiles:0,limitSize:mbToBytes(minSize()),fieldName:"wbupload",path:"files/Swiff.Uploader.swf",onLoad:function(){$("weaverbox-status").removeClass("hide");$("weaverbox-fallback").destroy()},debug:true,target:"weaverbox-browse",validateFile:function(file){if(!isValidExtension(getFileExtension(file.name))){alert("Invalid file type specified.");return false}if(!isValidFileSize(file.size)){alert("Max file size exceeded. The file size must not exceed "+minSize()+"MB");return false}return true},fileCreate:function(file,options){file.info=new Element("span",{"class":"file-info"});var trimmed_name=trimName(file.name);file.element=new Element("li",{"class":"file"}).adopt(new Element("span",{"class":"file-size",html:this.sizeToKB(file.size)}),new Element("a",{"class":"file-remove",href:"#",html:"Remove",events:{click:function(){this.removeFile(file);return false}.bind(this)}}),new Element("span",{"class":"file-name",html:trimmed_name}),new Element("label").adopt([new Element("span",{"class":"file-comment",html:"Comment:"}),new Element("input",{type:"text",name:"note",value:"",maxlength:"30",size:"30",events:{keyup:function(){var parent=this.getParent();var counter=parent.getElement("span.file-char-counter");counter.set("text",30-this.value.length)}}}),new Element("span",{"class":"file-char-counter",html:"30",id:"file-char-counter-number"})]),file.info).inject(this.list);file.element.highlight(highlightColor)},fileUpload:function(file,options){var inputs=file.element.getElements("input");options.data={};for(var i=0,j=inputs.length;i<j;i++){var input=inputs[i];options.data[input.name]=input.get("value")}return options},fileComplete:function(file,response){var data=JSON.decode(response);var status=data.UPLOAD_STATUS;if(status=="UPLOAD_ERROR"){file.element.addClass("file-failed");file.info.set("html",data.UPLOAD_MSG||"Unknown error")}else{if(status=="UPLOAD_SUCCESS"){file.element.addClass("file-success");file.info.set("html",data.UPLOAD_MSG)}}}});if(validFileExtensions.length>0){var joined_extensions=validFileExtensions.join(", ");$("weaverbox-accepted-file-type").set("html","Only files with the following extensions are permitted: "+joined_extensions);var description="Accepted file types ("+joined_extensions+")";filter={description:joined_extensions.replace(/\./g,"*.").replace(/,/g,";")};swiffy.options.typeFilter=filter;$("weaverbox-restricted-file-type").addClass("hide")}$("weaverbox-browse").addEvent("click",function(){swiffy.browse();return false});$("weaverbox-clear").addEvent("click",function(){swiffy.removeFile();resetUI(swiffy);swiffy.reposition();return false});$("weaverbox-upload").addEvent("click",function(){swiffy.upload();swiffy.reposition();return false})}}).get();window.onunload=null});