Generic=new new Class({buildPictureCommand:function(){this.contained=this.picture.getElements("img").removeEvents().addEvent("click",(function(A){if(this.editor.ready){this.editor.tinyMCE.activeEditor.selection.setContent('<img src="'+(A.target||A.srcElement).get("src").replace(/\/160x120\./,"/640x480.")+'"/>');}}).bindWithEvent(this)).length;this.picture.getElements(".picture .left a").removeEvents().addEvent("click",(function(A){if(this.editor.ready){this.editor.tinyMCE.activeEditor.selection.setContent('<img src="'+(A.target||A.srcElement).getParent("div.picture").getElement("img").get("src").replace(/\/160x120\./,"/"+(A.target||A.srcElement).get("text")+".")+'"/>');}return false;}).bindWithEvent(this));this.picture.getElements(".picture .right a").removeEvents().addEvent("click",(function(B){if(confirm("決定刪除?")){this.spinner.removeClass("invisible");var A=(B.target||B.srcElement).getParent("div.picture");new Request.JSON({onSuccess:(function(C){if(C&&C.code==200){A.destroy();this.spinner.addClass("invisible");}}).bind(this)}).send({url:"/action",data:{section:"share",action:"removePicture",id:A.get("id").replace(/picture/,"")}});}return false;}).bindWithEvent(this));},loadPicture:function(A){this.spinner.removeClass("invisible");if(A){this.picture.empty();}new Request.JSON({onSuccess:(function(B){if(B&&B.code==200){if(!B.pictures){this.pictureAllLoaded=true;}$each(B.pictures,(function(C){new Element("div",{id:"picture"+C.id,className:"picture"}).adopt([new Element("img",{title:"插入640x480px圖片",src:"/database/images/thumbs/160x120."+C.file}),new Element("div",{className:"functions"}).adopt([new Element("div",{className:"left"}).adopt([new Element("a",{title:"插入640x480px圖片",text:"640x480"}),new Element("a",{title:"插入320x240px圖片",text:"320x240"})]),new Element("div",{className:"right"}).adopt(new Element("a",{className:"alert",title:"刪除圖片",text:"(刪除)"})),new Element("div",{className:"clear"})])]).inject(this.picture);}).bind(this));this.buildPictureCommand();}}).bind(this),onComplete:(function(){this.spinner.addClass("invisible");}).bind(this)}).send({url:"/action",data:{section:"blog",action:"morePictures",start:A?0:this.contained}});},start:function(){if($("list")){if(!$("items")){alert("對不起，沒有找到匹配結果。請重新再試。");}Shared.searchReference.getElement("input[type=text]").select();this.changePasswordForm=$("changePasswordForm");this.passwords=this.changePasswordForm.getElements("input[type=password]").reverse();this.changePassword=$("changePassword").addEvent("click",(function(){this.changePassword.addClass("hidden");this.changePasswordForm.removeClass("hidden");this.passwords[2].select();return false;}).bind(this));this.changePasswordForm.addEvent("submit",(function(){try{this.emptyPassword=false;$each(this.passwords,function(C){if(!C.get("value")){C.focus();this.emptyPassword=true;}},this);if(this.emptyPassword){throw false;}if(this.passwords[0].get("value")!=this.passwords[1].get("value")){this.passwords[0].set("value","");this.passwords[1].set("value","").focus();throw"新密碼輸入錯誤，請再輸入!";}new Request.JSON({onSuccess:(function(C){if(C&&C.code==200){this.changePasswordForm.addClass("hidden");this.changePassword.removeClass("hidden");alert("密碼已成功變更!");}else{alert("密碼驗証失敗，請再輸入!");this.passwords[2].select();}}).bind(this)}).send({url:"/action",data:this.changePasswordForm.toQueryString()});}catch(B){if(B){alert(B);}}return false;}).bind(this)).getElement("a").addEvent("click",(function(){this.changePasswordForm.addClass("hidden");this.changePassword.removeClass("hidden");return false;}).bind(this));}else{if($("logon")){this.logon=$("logon");var A=this.logon.getElement("input[type=text]");if(A.get("value")){this.logon.getElement("input[type=password]").focus();}else{A.focus();}}else{if($("post")){this.post=$("post");this.spinner=$("control").getElement(".spinner");this.editor=$("editor").removeClass("hidden");this.textarea=this.post.getElement("textarea").addClass("hidden");this.picture=$("pictures").addEvent("scroll",(function(){this.displayed=((this.picture.getSize()["y"]+this.picture.getScroll()["y"])/this.picture.getElement(".picture").getSize()["y"]).toInt();if(this.contained-this.displayed<=2&&this.spinner.hasClass("invisible")&&!this.pictureAllLoaded){this.loadPicture();}}).bind(this));this.uploader=new Uploader({path:"/prepared/flashes/0c8e.swf",url:"/action/"+Cookie.read("sid"),target:$("upload"),typeFilter:{"Images (*.jpg, *.jpeg, *.gif, *.png)":"*.jpg; *.jpeg; *.gif; *.png"},onAllComplete:(function(){this.spinner.addClass("invisible");this.uploader.reposition();this.loadPicture(true);}).bind(this),onUpdate:(function(){this.spinner.removeClass("invisible");this.uploader.disable();this.uploader.upload({data:{section:"share",action:"uploadPicture"}});}).bind(this)});this.post.addEvent("submit",(function(){this.spinner.removeClass("invisible");this.textarea.set("value",this.editor.tinyMCE.activeEditor.getContent());new Request.JSON({onSuccess:(function(B){if(B&&B.code==200){this.spinner.addClass("invisible");alert("儲存完成!");window.location=B.url;}}).bind(this)}).send({url:"/action",data:this.post.toQueryString()});return false;}).bind(this));this.waitUntilLoaded=(function(){if(this.editor.contentWindow.loaded){$clear(this.waitUntilLoaded);this.editor=this.editor.contentWindow;this.waitUntilReady=(function(){if(this.editor.ready){$clear(this.waitUntilReady);this.editor.tinyMCE.activeEditor.setContent(this.textarea.get("text"));this.spinner.addClass("invisible");}}).periodical(20,this);}}).periodical(20,this);this.buildPictureCommand();}}}}});window.addEvent("domready",Generic.start.bind(Generic));
