(function(){function B(H,G,E){for(var F=0;F<H.toolbox.toolbars.length;F++){var J=H.toolbox.toolbars[F];for(var D=0;D<J.items.length;D++){var I=J.items[D];if((G=="button"&&I.button&&I.button.label==E)){return I}}}}function A(D,E){this.editor=D;CKEDITOR.dialog.add("attachment",E+"dialogs/attachment.js?v="+SIMPLEVERSION);D.addCommand("openAttachmentConfig",new CKEDITOR.dialogCommand("attachment"))}function C(D,E){this.editor=D;this.attachmentConfig=E}C.prototype={windows:new Array(),exec:function(E){this.content=CKEDITOR.config.content;if(AJAX_Compatible&&this.content.enhanced==1){var D=!E.config.nobbcode?this.content.insertinline:0;this.open_window("newattachment.php?"+SESSIONURL+"do=assetmanager&"+PHP.unhtmlspecialchars(this.content.values)+"&contenttypeid="+this.content.contenttypeid+"&poststarttime="+this.content.poststarttime+"&posthash="+this.content.posthash+"&insertinline="+D,725,520,this.content.contenttypeid+"_"+this.content.posthash)}else{this.open_window("newattachment.php?"+SESSIONURL+PHP.unhtmlspecialchars(this.content.values)+"&contenttypeid="+this.content.contenttypeid+"&poststarttime="+this.content.poststarttime+"&posthash="+this.content.posthash,480,480,this.content.posthash)}},open_window:function(E,F,D,G){if(this.windows[G]&&this.windows[G].closed==false){this.windows[G].focus()}else{this.windows[G]=openWindow(E,F,D,"Attach"+G)}},insert_attachment:function(D,E){this.editor.insert_attachment(D,E)}};CKEDITOR.editor.prototype.insert_attachment=function(E,J){var I=(J!=0)?"[ATTACH=CONFIG]"+E+"[/ATTACH]":"[ATTACH]"+E+"[/ATTACH]";if(this.mode=="wysiwyg"&&CKEDITOR.env.gecko&&parseInt(navigator.productSub)<=20100924&&parseInt(navigator.productSub)>=20100721){var F=this.dataProcessor.toHtml(I);var H=this.getSelection();var G=H.createBookmarks();var D=new CKEDITOR.dom.element("span");D.setHtml(F);D.insertBefore(G[0].startNode);D.remove(true);H.selectBookmarks(G)}else{this.insertHtml(I)}};CKEDITOR.plugins.add("attachment",{init:function(J){var F;var D;var O=new A(J,J.config.vbPluginPath+"attachment/");var L=new C(J,O);window.ckeattachment=L;J.addCommand("openAttachmentWindow",L);var K=function(P){J.execCommand("openAttachmentWindow");P.cancel();P.stop();P.data.preventDefault(true);return false};var M;var N;var E;J.on("instanceReady",function(Q){E=B(J,"button",J.config.vbulletin.phrase.attachments);if(E){var P=CKEDITOR.document.getById(E.id);M=P.getChild(0);M.on("click",K,null,null,1);N=P.getChild(2);N.on("click",function(R){if(vB_Attachments.attachments.length==0||J.config.nobbcode){K(R)}},null,null,1);E.button.onOpen=function(){if(F){F.element.setHtml(I());D.element.getFirst().addClass("cke_attach")}}}},this);var H=CKEDITOR.tools.addFunction(function(P){J.insert_attachment(P)});var G=CKEDITOR.tools.addFunction(function(){if(vB_Attachments){for(var P in vB_Attachments.attachments){J.insert_attachment(P)}}});function I(){var P=[];if(vB_Attachments){var Q=0;for(var R in vB_Attachments.attachments){Q++;P.push('<a href="" onclick="CKEDITOR.tools.callFunction(',H,", ",R,');return false;">');P.push(vB_Attachments.attachments[R]["html"]);P.push("</a>")}if(Q>1){P.push('<div class="attach_insert_all" onclick="CKEDITOR.tools.callFunction(',G,')">',J.lang.vbulletin.insert_all,"</div>")}}return P.join("")}J.ui.add("Attach",CKEDITOR.UI_PANELBUTTON,{label:J.config.vbulletin.phrase.attachments,title:J.config.vbulletin.phrase.attachments,className:"cke_button_openAttachmentWindow",modes:{wysiwyg:1,enhancedsource:1},panel:{css:J.config.vbulletin.bburl+"/css.php?sheet=bbcode.css,editor.css,popupmenu.css,reset-fonts.css,vbulletin.css,vbulletin-chrome.css,vbulletin-formcontrols.css",attributes:{role:"listbox","aria-label":J.config.vbulletin.phrase.attachments},onLoad:function(){D=E.button._.panel;if(D){D.element.getFirst().addClass("cke_attach")}}},onBlock:function(Q,P){D=Q;F=P;F.autoSize=true;F.element.addClass("editorpopupbody");D.element.getFirst().addClass("cke_attach");F.element.getDocument().getBody().setStyle("overflow","hidden");if(F.element.getDocument().getHead().getChild(0)){F.element.getDocument().getHead().getChild(0).remove()}var R=F.keys;var S=J.lang.dir=="rtl";R[S?37:39]="next";R[40]="next";R[9]="next";R[S?39:37]="prev";R[38]="prev";R[CKEDITOR.SHIFT+9]="prev";R[32]="click"}})}})})();