CKEDITOR.dialog.add("colordialog",function(g){function E(){N.getById(o).removeStyle("background-color");k.getContentElement("picker","selectedColor").setValue("");J&&J.removeAttribute("aria-selected");J=null}function c(d){d=d.data.getTarget();var e;"td"==d.getName()&&(e=d.getChild(0).getHtml())&&(J=d,J.setAttribute("aria-selected",!0),k.getContentElement("picker","selectedColor").setValue(e))}function D(e){e=e.replace(/^#/,"");for(var f=0,d=[];2>=f;f++){d[f]=parseInt(e.substr(2*f,2),16)}return"#"+(165<=0.2126*d[0]+0.7152*d[1]+0.0722*d[2]?"000":"fff")}function b(e){!e.name&&(e=new CKEDITOR.event(e));var h=!/mouse/.test(e.name),d=e.data.getTarget(),f;"td"==d.getName()&&(f=d.getChild(0).getHtml())&&(j(e),h?M=d:a=d,h&&(d.setStyle("border-color",D(f)),d.setStyle("border-style","dotted")),N.getById(I).setStyle("background-color",f),N.getById(H).setHtml(f))}function j(d){if(d=!/mouse/.test(d.name)&&M){var e=d.getChild(0).getHtml();d.setStyle("border-color",e);d.setStyle("border-style","solid")}M||a||(N.getById(I).removeStyle("background-color"),N.getById(H).setHtml("&nbsp;"))}function v(f){var m=f.data,e=m.getTarget(),h=m.getKeystroke(),l="rtl"==g.lang.dir;switch(h){case 38:if(f=e.getParent().getPrevious()){f=f.getChild([e.getIndex()]),f.focus()}m.preventDefault();break;case 40:(f=e.getParent().getNext())&&(f=f.getChild([e.getIndex()]))&&1==f.type&&f.focus();m.preventDefault();break;case 32:case 13:c(f);m.preventDefault();break;case l?37:39:(f=e.getNext())?1==f.type&&(f.focus(),m.preventDefault(!0)):(f=e.getParent().getNext())&&(f=f.getChild([0]))&&1==f.type&&(f.focus(),m.preventDefault(!0));break;case l?39:37:if(f=e.getPrevious()){f.focus(),m.preventDefault(!0)}else{if(f=e.getParent().getPrevious()){f=f.getLast(),f.focus(),m.preventDefault(!0)}}}}var i=CKEDITOR.dom.element,N=CKEDITOR.document,L=g.lang.colordialog,k,F={type:"html",html:"&nbsp;"},J,M,a,G=function(d){return CKEDITOR.tools.getNextId()+"_"+d},I=G("hicolor"),H=G("hicolortext"),o=G("selhicolor"),K;(function(){function h(q,w){for(var r=q;r<q+3;r++){var u=new i(K.$.insertRow(-1));u.setAttribute("role","row");for(var t=w;t<w+3;t++){for(var s=0;6>s;s++){p(u.$,"#"+f[t]+f[s]+f[r])}}}}function p(q,s){var e=new i(q.insertCell(-1));e.setAttribute("class","ColorCell");e.setAttribute("tabIndex",-1);e.setAttribute("role","gridcell");e.on("keydown",v);e.on("click",c);e.on("focus",b);e.on("blur",j);e.setStyle("background-color",s);e.setStyle("border","1px solid "+s);e.setStyle("width","14px");e.setStyle("height","14px");var r=G("color_table_cell");e.setAttribute("aria-labelledby",r);e.append(CKEDITOR.dom.element.createFromHtml('<span id="'+r+'" class="cke_voice_label">'+s+"</span>",CKEDITOR.document))}K=CKEDITOR.dom.element.createFromHtml('<table tabIndex="-1" aria-label="'+L.options+'" role="grid" style="border-collapse:separate;" cellspacing="0"><caption class="cke_voice_label">'+L.options+'</caption><tbody role="presentation"></tbody></table>');K.on("mouseover",b);K.on("mouseout",j);var f="00 33 66 99 cc ff".split(" ");h(0,0);h(3,0);h(0,3);h(3,3);var n=new i(K.$.insertRow(-1));n.setAttribute("role","row");p(n.$,"#000000");for(var m=0;16>m;m++){var l=m.toString(16);p(n.$,"#"+l+l+l+l+l+l)}p(n.$,"#ffffff")})();return{title:L.title,minWidth:360,minHeight:220,onLoad:function(){k=this},onHide:function(){E();var d=M.getChild(0).getHtml();M.setStyle("border-color",d);M.setStyle("border-style","solid");N.getById(I).removeStyle("background-color");N.getById(H).setHtml("&nbsp;");M=null},contents:[{id:"picker",label:L.title,accessKey:"I",elements:[{type:"hbox",padding:0,widths:["70%","10%","30%"],children:[{type:"html",html:"<div></div>",onLoad:function(){CKEDITOR.document.getById(this.domId).append(K)},focus:function(){(M||this.getElement().getElementsByTag("td").getItem(0)).focus()}},F,{type:"vbox",padding:0,widths:["70%","5%","25%"],children:[{type:"html",html:"<span>"+L.highlight+'</span><div id="'+I+'" style="border: 1px solid; height: 74px; width: 74px;"></div><div id="'+H+'">&nbsp;</div><span>'+L.selected+'</span><div id="'+o+'" style="border: 1px solid; height: 20px; width: 74px;"></div>'},{type:"text",label:L.selected,labelStyle:"display:none",id:"selectedColor",style:"width: 76px;margin-top:4px",onChange:function(){try{N.getById(o).setStyle("background-color",this.getValue())}catch(d){E()}}},F,{type:"button",id:"clear",label:L.clear,onClick:E}]}]}]}]}});