window.addEvent("domready",function(){var login=document.id("weaverbox-modal");if(login){login.setStyles({opacity:0,display:"block"});login.fade("in");if(loginAttempt){login.shake("margin",5,3)}document.id("login").addEvent("submit",function(e){var challenge="weaverbox";var pw=document.id("wbox_challenge").get("value");document.id("wbox_password").set("value",hex_md5(hex_md5(pw)+challenge));document.id("wbox_challenge").set("value","");this.send()})}var flash=document.id("weaverbox-flash-version");if(flash){flash.appendText(Browser.Plugins.Flash.version);var jsonRequest=new Request.JSON({url:"clientdropbox_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;var lang=data.LANGUAGE;var hideRest=data.HIDE_RESTRICTIONS;var commentLength=data.COMMENT_LENGTH;function setLanguage(lang){var curr=MooTools.lang.getCurrentLanguage().toLowerCase();if(lang.toLowerCase()!=curr){MooTools.lang.setLanguage(lang)}}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.overallProgress.set(0);obj.currentProgress.set(0)}setLanguage(lang);var filter;if(validFileExtensions.length>0){var joined_extensions=validFileExtensions.join(", ");document.id("weaverbox-accepted-file-type").appendText(joined_extensions);var description="Accepted file types ("+joined_extensions+")";filter={description:joined_extensions.replace(/\./g,"*.").replace(/,/g,";")};document.id("weaverbox-restricted-file-type").addClass("hide")}else{document.id("weaverbox-accepted-file-type").addClass("hide")}document.id("weaverbox-max_upload_size").appendText(minSize()+"MB");document.id("weaverbox-restricted-file-type").appendText(invalidFileExtensions.join(", "));var swiffy=new FancyUpload2(document.id("weaverbox-status"),document.id("weaverbox-list"),{url:document.id("form-weaverbox").action,limitFiles:0,limitSize:mbToBytes(minSize()),fieldName:"wbupload",path:"clientdropbox_files/Swiff.Uploader.swf",typeFilter:filter,onLoad:function(){document.id("weaverbox-status").removeClass("hide");document.id("weaverbox-fallback").destroy();if(hideRest===true){document.id("weaverbox-file-restrictions").destroy()}document.id("weaverbox-clear").addEvent("click",function(){swiffy.remove();resetUI(swiffy);return false});document.id("weaverbox-upload").addEvent("click",function(){swiffy.start();return false})},verbose:false,target:"weaverbox-browse",validateFile:function(file){if(!isValidExtension(getFileExtension(file.name))){alert(MooTools.lang.get("weaverBox","invalidFileType"));return false}if(!isValidFileSize(file.size)){alert(MooTools.lang.get("weaverBox","maxFileSize")+minSize()+"MB");return false}return true},onSelectSuccess:function(files){files.each(function(file){var trimmed_name=trimName(file.name);var el=file.element;el.getElement(".file-name").set("html",trimmed_name);el.adopt(new Element("label").adopt([new Element("span",{"class":"file-comment",html:MooTools.lang.get("weaverBox","comment")}),new Element("input",{type:"text",name:"note",value:"",maxlength:commentLength,size:"30",events:{keyup:function(){var parent=this.getParent();var counter=parent.getElement("span.file-char-counter");counter.set("text",commentLength-this.value.length)}}}),new Element("span",{"class":"file-char-counter",html:commentLength})]));el.highlight(highlightColor)})},onBeforeStart:function(file){var files=this.fileList;files.each(function(file){var inputs=file.element.getElements("input");inputs.each(function(input){var hash=new Hash();hash.set(input.name,input.get("value"));file.setOptions({data:hash})})})},onFileSuccess: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||MooTools.lang.get("weaverBox","unknownError"))}else{if(status=="UPLOAD_SUCCESS"){file.element.addClass("file-success");file.info.set("html",data.UPLOAD_MSG)}}},onFail:function(error){switch(error){case"hidden":alert(MooTools.lang.get("weaverBox","adBlock"));break;case"blocked":alert(MooTools.lang.get("weaverBox","flashBlock"));break;case"empty":alert(MooTools.lang.get("weaverBox","fileNotFound"));break;case"flash":alert(MooTools.lang.get("weaverBox","noFlash"))}},onSelectFail:function(files){files.each(function(file){new Element("li",{"class":"validation-error",html:file.validationErrorMessage||file.validationError,title:MooTools.lang.get("FancyUpload","removeTitle"),events:{click:function(){this.destroy()}}}).inject(this.list,"top")},this)}});if(!swiffy){document.id("form-weaverbox").addEvent("submit",function(e){e.stop();this.set("send",{onComplete:function(response){var data=JSON.decode(response);document.id("weaverbox-fallback-message").set("html","<p><i>"+data.UPLOAD_MSG+"</i></p>")}});this.send()})}}}).get()}window.onunload=null});
