var WallOfFameZone=Class.create();WallOfFameZone.prototype={progress_bar:null,updates:null,initialize:function(){},initDefault:function(){this.initProgressBar();$$(".hide").invoke("hide");this.form=new JsonForm("zone_wall_of_fame.form",{scroll_to_error:"first",process_page:"/wall-of-fame/submit",onSubmitSuccess:this.stepTwoComplete.bind(this)})},initProgressBar:function(){try{this.progress_bar=new Control.ProgressBar("progress_bar")}catch(a){this.progress_bar=null;$("progress_bar").hide()}},initFileProgress:function(){centerElement("progress_bar_container");centerCover();displayCover();$("progress_bar_container").show();$("progress_bar_text").update("Starting Upload...");this.updates=new Ajax.PeriodicalUpdater("upload_progress","/wall-of-fame/upload-progress",{method:"get",frequency:0.5,decay:0,onSuccess:this.update.bind(this)})},getSubmitStatus:function(){this.check=new Ajax.Request("/wall-of-fame/submit-status",{method:"get",onComplete:function(b){var a=b.responseText.evalJSON(true);if(a.file_accepted==true){zone_wall_of_fame.stepOneComplete()}if(a.image==true){$("editor-iframe").show();mcImageManager.edit({target_frame:"editor-iframe",path:"{0}/"+a.file,onsave:function(c){new Ajax.Request("/wall-of-fame/edit-save")}})}}})},update:function(c){this.progress_bar.step(100);var e=c.responseText.evalJSON(true);var b=e.message.evalJSON();var a=Math.round((parseInt(b.current)/parseInt(b.total))*100);if(isNaN(a)){a=0}var d=$("progress_bar_text");if(b.done==true){d.update("Upload Complete!");this.closeFileProgress();this.updates.stop();this.getSubmitStatus();this.closeFileProgress()}else{if(!isNaN(a)){d.update("Upload "+a+"% Complete...")}else{d.update("Upload In Progress...")}}},closeFileProgress:function(){$("progress_bar_container").hide();hideCover()},submitFile:function(){$("walloffame_file").submit();if(!Object.isUndefined(parent)){parent.zone_wall_of_fame.initFileProgress()}},stepOneComplete:function(){$$("step-1").invoke("hide")},stepTwoComplete:function(){document.location.href="/wall-of-fame/thank-you"},getFrameDocument:function(){if(Object.isUndefined(frames.file_frame)){return $("file_frame").contentDocument}return frames.file_frame.document},getFrameBody:function(){return this.getFrameDocument().body},initFileListeners:function(){var a=$("file");if(a){a.observe("change",this.submitFile.bind(this))}}};zone_wall_of_fame=new WallOfFameZone();
if(typeof(Prototype)=="undefined"){throw"Control.ProgressBar requires Prototype to be loaded."}if(typeof(Object.Event)=="undefined"){throw"Control.ProgressBar requires Object.Event to be loaded."}Control.ProgressBar=Class.create({initialize:function(a,b){this.progress=0;this.executer=false;this.active=false;this.poller=false;this.container=$(a);this.containerWidth=this.container.getDimensions().width-(parseInt(this.container.getStyle("border-right-width").replace(/px/,""),10)+parseInt(this.container.getStyle("border-left-width").replace(/px/,""),10));this.progressContainer=$(document.createElement("div"));this.progressContainer.setStyle({width:this.containerWidth+"px",height:"100%",position:"absolute",top:"0px",right:"0px"});this.container.appendChild(this.progressContainer);this.options={afterChange:Prototype.emptyFunction,interval:0.25,step:1,classNames:{active:"progress_bar_active",inactive:"progress_bar_inactive"}};Object.extend(this.options,b||{});this.container.addClassName(this.options.classNames.inactive);this.active=false},setProgress:function(a){this.progress=a;this.draw();if(this.progress>=100){this.stop(false)}this.notify("afterChange",this.progress,this.active)},poll:function(c,b,a){a=a||{};var d=a.onSuccess||Prototype.emptyFunction;a.onSuccess=d.wrap(function(e,f){this.setProgress(parseInt(f.responseText,10));if(!this.active){this.poller.stop()}e(f)}).bind(this);this.active=true;this.poller=new PeriodicalExecuter(function(){var e=new Ajax.Request(c,a)}.bind(this),b||3)},start:function(){this.active=true;this.container.removeClassName(this.options.classNames.inactive);this.container.addClassName(this.options.classNames.active);this.executer=new PeriodicalExecuter(this.step.bind(this,this.options.step),this.options.interval)},stop:function(a){this.active=false;if(this.executer){this.executer.stop()}this.container.removeClassName(this.options.classNames.active);this.container.addClassName(this.options.classNames.inactive);if(typeof a==="undefined"||a===true){this.reset()}},step:function(a){this.active=true;this.setProgress(Math.min(100,this.progress+a))},reset:function(){this.active=false;this.setProgress(0)},draw:function(){this.progressContainer.setStyle({width:(this.containerWidth-Math.floor((parseInt(this.progress,10)/100)*this.containerWidth))+"px"})},notify:function(a){if(this.options[a]){return[this.options[a].apply(this.options[a],$A(arguments).slice(1))]}}});Object.Event.extend(Control.ProgressBar);
