NEW_CKEDITOR.dialog.add("templates",(function(e){function t(e,t){var l=NEW_CKEDITOR.dom.element.createFromHtml('<a href="javascript:void(0)" tabIndex="-1" role="option" ><div class="edi_tpl_item"></div></a>'),i='<table style="width:350px;" class="edi_tpl_preview" role="presentation"><tr>';return e.image&&t&&(i+='<td class="edi_tpl_preview_img"><img src="'+NEW_CKEDITOR.getUrl(t+e.image)+'"'+(NEW_CKEDITOR.env.ie6Compat?' onload="this.width=this.width"':"")+' alt="" title=""></td>'),i+='<td style="white-space:normal;"><span class="edi_tpl_title">'+e.title+"</span><br/>",e.description&&(i+="<span>"+e.description+"</span>"),i+="</td></tr></table>",l.getFirst().setHtml(i),l.on("click",(function(){if(e.htmlFile){var t=NEW_CKEDITOR.dialog.getCurrent();t.setState(NEW_CKEDITOR.DIALOG_STATE_BUSY),NEW_CKEDITOR.ajax.loadText(e.htmlFile,(function(e){a(e),t.setState(NEW_CKEDITOR.DIALOG_STATE_IDLE)}))}else a(e.html)})),l}function a(t){var a=NEW_CKEDITOR.dialog.getCurrent();a.getValueOf("selectTpl","chkInsertOpt")?(e.fire("saveSnapshot"),e.setData(t,(function(){a.hide();var t=e.createRange();t.moveToElementEditStart(e.editable()),t.select(),setTimeout((function(){e.fire("saveSnapshot")}),0)}))):(e.insertHtml(t),a.hide())}function l(e){var t=e.data.getTarget(),a=s.equals(t);if(a||s.contains(t)){var l,i=e.data.getKeystroke(),n=s.getElementsByTag("a");if(n){if(a)l=n.getItem(0);else switch(i){case 40:l=t.getNext();break;case 38:l=t.getPrevious();break;case 13:case 32:t.fire("click")}l&&(l.focus(),e.data.preventDefault())}}}var i=NEW_CKEDITOR.plugins.get("templates");NEW_CKEDITOR.document.appendStyleSheet(NEW_CKEDITOR.getUrl(i.path+"dialogs/templates.css")),i="edi_tpl_list_label_"+NEW_CKEDITOR.tools.getNextNumber();var s,n=e.lang.templates,o=e.config;return{title:e.lang.templates.title,minWidth:NEW_CKEDITOR.env.ie?440:400,minHeight:340,contents:[{id:"selectTpl",label:n.title,elements:[{type:"vbox",padding:5,children:[{id:"chkInsertOpt",type:"checkbox",label:n.insertOption,default:o.templates_replaceContent},{id:"selectTplText",type:"html",html:"<span>"+n.selectPromptMsg+"</span>"},{id:"templatesList",type:"html",focus:!0,html:'<div class="edi_tpl_list" tabIndex="-1" role="listbox" aria-labelledby="'+i+'"><div class="edi_tpl_loading"><span></span></div></div><span class="edi_voice_label" id="'+i+'">'+n.options+"</span>"}]}]}],buttons:[NEW_CKEDITOR.dialog.cancelButton],onShow:function(){var e=this.getContentElement("selectTpl","templatesList");s=e.getElement(),NEW_CKEDITOR.loadTemplates(o.templates_files,(function(){var a=(o.templates||"default").split(",");if(a.length){var l=s;l.setHtml("");for(var i=0,p=a.length;i<p;i++)for(var r,d=(r=NEW_CKEDITOR.getTemplates(a[i])).imagesPath,c=(r=r.templates).length,m=0;m<c;m++){var _=t(r[m],d);_.setAttribute("aria-posinset",m+1),_.setAttribute("aria-setsize",c),l.append(_)}e.focus()}else s.setHtml('<div class="edi_tpl_empty"><span>'+n.emptyListMsg+"</span></div>")})),this._.element.on("keydown",l)},onHide:function(){this._.element.removeListener("keydown",l)}}}));