!function(){function e(e){do{if(e.className&&-1!=e.className.indexOf("mceItemLayer"))return e}while(e=e.parentNode)}tinymce.create("tinymce.plugins.Layer",{init:function(t,o){var i=this;i.editor=t,t.addCommand("mceInsertLayer",i._insertLayer,i),t.addCommand("mceMoveForward",(function(){i._move(1)})),t.addCommand("mceMoveBackward",(function(){i._move(-1)})),t.addCommand("mceMakeAbsolute",(function(){i._toggleAbsolute()})),t.addButton("moveforward",{title:"layer.forward_desc",cmd:"mceMoveForward"}),t.addButton("movebackward",{title:"layer.backward_desc",cmd:"mceMoveBackward"}),t.addButton("absolute",{title:"layer.absolute_desc",cmd:"mceMakeAbsolute"}),t.addButton("insertlayer",{title:"layer.insertlayer_desc",cmd:"mceInsertLayer"}),t.onInit.add((function(){t.dom;tinymce.isIE&&t.getDoc().execCommand("2D-Position",!1,!0)})),t.onMouseUp.add((function(t,o){var i=e(o.target);i&&t.dom.setAttrib(i,"data-mce-style","")})),t.onMouseDown.add((function(t,o){var i,n=o.target,a=t.getDoc();tinymce.isGecko&&(e(n)?"on"!==a.designMode&&(a.designMode="on",(i=(n=a.body).parentNode).removeChild(n),i.appendChild(n)):"on"==a.designMode&&(a.designMode="off"))})),t.onNodeChange.add(i._nodeChange,i),t.onVisualAid.add(i._visualAid,i)},getInfo:function(){return{longname:"Layer",author:"Moxiecode Systems AB",authorurl:"http://tinymce.moxiecode.com",infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer",version:tinymce.majorVersion+"."+tinymce.minorVersion}},_nodeChange:function(e,t,o){var i;i=this._getParentLayer(o),e.dom.getParent(o,"DIV,P,IMG")?(t.setDisabled("absolute",0),t.setDisabled("moveforward",!i),t.setDisabled("movebackward",!i),t.setActive("absolute",i&&"absolute"==i.style.position.toLowerCase())):(t.setDisabled("absolute",1),t.setDisabled("moveforward",1),t.setDisabled("movebackward",1))},_visualAid:function(e,t,o){var i=e.dom;tinymce.each(i.select("div,p",t),(function(e){/^(absolute|relative|fixed)$/i.test(e.style.position)&&(o?i.addClass(e,"mceItemVisualAid"):i.removeClass(e,"mceItemVisualAid"),i.addClass(e,"mceItemLayer"))}))},_move:function(e){var t,o,i=this.editor,n=[],a=this._getParentLayer(i.selection.getNode()),d=-1,s=-1;for(o=[],tinymce.walk(i.getBody(),(function(e){1==e.nodeType&&/^(absolute|relative|static)$/i.test(e.style.position)&&o.push(e)}),"childNodes"),t=0;t<o.length;t++)n[t]=o[t].style.zIndex?parseInt(o[t].style.zIndex):0,d<0&&o[t]==a&&(d=t);if(e<0){for(t=0;t<n.length;t++)if(n[t]<n[d]){s=t;break}s>-1?(o[d].style.zIndex=n[s],o[s].style.zIndex=n[d]):n[d]>0&&(o[d].style.zIndex=n[d]-1)}else{for(t=0;t<n.length;t++)if(n[t]>n[d]){s=t;break}s>-1?(o[d].style.zIndex=n[s],o[s].style.zIndex=n[d]):o[d].style.zIndex=n[d]+1}i.execCommand("mceRepaint")},_getParentLayer:function(e){return this.editor.dom.getParent(e,(function(e){return 1==e.nodeType&&/^(absolute|relative|static)$/i.test(e.style.position)}))},_insertLayer:function(){var e=this.editor,t=e.dom,o=t.getPos(t.getParent(e.selection.getNode(),"*")),i=e.getBody();e.dom.add(i,"div",{style:{position:"absolute",left:o.x,top:o.y>20?o.y:20,width:100,height:100},class:"mceItemVisualAid mceItemLayer"},e.selection.getContent()||e.getLang("layer.content")),tinymce.isIE&&t.setHTML(i,i.innerHTML)},_toggleAbsolute:function(){var e=this.editor,t=this._getParentLayer(e.selection.getNode());t||(t=e.dom.getParent(e.selection.getNode(),"DIV,P,IMG")),t&&("absolute"==t.style.position.toLowerCase()?(e.dom.setStyles(t,{position:"",left:"",top:"",width:"",height:""}),e.dom.removeClass(t,"mceItemVisualAid"),e.dom.removeClass(t,"mceItemLayer")):(""==t.style.left&&(t.style.left="20px"),""==t.style.top&&(t.style.top="20px"),""==t.style.width&&(t.style.width=t.width?t.width+"px":"100px"),""==t.style.height&&(t.style.height=t.height?t.height+"px":"100px"),t.style.position="absolute",e.dom.setAttrib(t,"data-mce-style",""),e.addVisual(e.getBody())),e.execCommand("mceRepaint"),e.nodeChanged())}}),tinymce.PluginManager.add("layer",tinymce.plugins.Layer)}();
