var tinymce=null,tinyMCEPopup,tinyMCE,wpImage;tinyMCEPopup={init:function(){var d=this,b,a,f,c,e;a=(""+document.location.search).replace(/^\?/,"").split("&");f={};for(c=0;cparseInt(b.preloadImg.width)){d=b.I("s130"),c=b.I("s120"),a=b.I("s110");d.onclick=c.onclick=a.onclick=null;d.onmouseover=c.onmouseover=a.onmouseover=null;d.style.color=c.style.color=a.style.color="#aaa"}},showSizeRem:function(){var a=this,c=a.I("img_demo"),b=document.forms[0];c.width=Math.round(b.width.value*0.5);c.height=Math.round(b.height.value*0.5);a.showSizeClear();a.I(a.current_size_sel).style.borderColor="#A3A3A3";a.I(a.current_size_sel).style.backgroundColor="#E5E5E5";return false},showSizeClear:function(){var b=this.I("img_size").getElementsByTagName("div"),a;for(a=0;a/,"").replace(/<\/p>$/,"")}}k.img_cap_text.value=r;k.img_title.value=j.dom.getAttrib(e,"title");k.img_alt.value=j.dom.getAttrib(e,"alt");k.border.value=j.dom.getAttrib(e,"border");k.vspace.value=j.dom.getAttrib(e,"vspace");k.hspace.value=j.dom.getAttrib(e,"hspace");k.align.value=j.dom.getAttrib(e,"align");k.width.value=s.width=j.dom.getAttrib(e,"width");k.height.value=s.height=j.dom.getAttrib(e,"height");k.img_classes.value=n;k.img_style.value=j.dom.getAttrib(e,"style");if(i.getAttrib(e,"hspace")){s.updateStyle("hspace")}if(i.getAttrib(e,"border")){s.updateStyle("border")}if(i.getAttrib(e,"vspace")){s.updateStyle("vspace")}if(p=j.dom.getParent(e,"A")){k.link_href.value=s.current=j.dom.getAttrib(p,"href");k.link_title.value=j.dom.getAttrib(p,"title");k.link_rel.value=s.link_rel=j.dom.getAttrib(p,"rel");k.link_style.value=j.dom.getAttrib(p,"style");s.target_value=j.dom.getAttrib(p,"target");k.link_classes.value=j.dom.getAttrib(p,"class")}k.link_target.checked=(s.target_value&&s.target_value=="_blank")?"checked":"";g=o.substring(o.lastIndexOf("/"));g=g.replace(/-[0-9]{2,4}x[0-9]{2,4}/,"");s.link=o.substring(0,o.lastIndexOf("/"))+g;if(n.indexOf("alignleft")!=-1){s.I("alignleft").checked="checked";m.className=s.align="alignleft"}else{if(n.indexOf("aligncenter")!=-1){s.I("aligncenter").checked="checked";m.className=s.align="aligncenter"}else{if(n.indexOf("alignright")!=-1){s.I("alignright").checked="checked";m.className=s.align="alignright"}else{if(n.indexOf("alignnone")!=-1){s.I("alignnone").checked="checked";m.className=s.align="alignnone"}}}}if(s.width&&s.preloadImg.width){s.showSizeSet()}document.body.style.display="";tinyMCEPopup.events.add(document.body,"click",function(v){var w=v.target,z=w.parentNode,y,x,t,A,f,B,u,d;if(i.hasClass(w,"caption-insert-link")){t=i.select("div.caption-insert-link-wrap",z)[0],A=i.select("#img_cap_text")[0];if(document.selection){A.focus();f=document.selection.createRange();l=f.getBookmark();if(f.text){i.select(".caption-insert-link-text",t)[0].value=f.text}}else{if(A.selectionStart||A.selectionStart=="0"){B=A.value;u=A.selectionStart;d=A.selectionEnd;if(u!=d){i.select(".caption-insert-link-text",t)[0].value=B.substring(u,d)}}}i.hide(w);i.show(t);i.select(".caption-insert-link-url",t)[0].focus()}else{if(i.hasClass(w,"caption-cancel")||i.hasClass(w,"caption-save")){if(i.hasClass(w,"caption-save")){b()}i.hide(i.select(".caption-insert-link-wrap"));i.show(i.select(".caption-insert-link"))}}});b=function(){var u,v,w,f,t,y,x=i.select("#img_cap_text")[0],d=i.select(".caption-insert-link-url")[0],c=i.select(".caption-insert-link-text")[0];if(!d||!c){return}v=""+c.value+"";if(document.selection){x.focus();u=document.selection.createRange();if(l){u.moveToBookmark(l);l=""}u.text=v;x.focus()}else{if(x.selectionStart||x.selectionStart=="0"){y=x.value;w=x.selectionStart;f=x.selectionEnd;t=x.scrollTop;x.value=y.substring(0,w)+v+y.substring(f,y.length);x.focus();x.selectionStart=w+v.length;x.selectionEnd=w+v.length;x.scrollTop=t}}d.value="";c.value=""}},remove:function(){var a=tinyMCEPopup.editor,c,b;tinyMCEPopup.restoreSelection();b=a.selection.getNode();if(b.nodeName!="IMG"){return}if((c=a.dom.getParent(b,"div"))&&a.dom.hasClass(c,"mceTemp")){a.dom.remove(c)}else{if((c=a.dom.getParent(b,"A"))&&c.childNodes.length==1){a.dom.remove(c)}else{a.dom.remove(b)}}a.execCommand("mceRepaint");tinyMCEPopup.close();return},update:function(){var m=this,v=document.forms[0],g=tinyMCEPopup.editor,e,x,d=null,n,h,p,r,o=null,k=v.img_classes.value,l,q,u="",j,i,s,a,z,w="",c,y;tinyMCEPopup.restoreSelection();e=g.selection.getNode();if(e.nodeName!="IMG"){return}if(v.img_src.value===""){m.remove();return}if(v.img_cap_text.value!=""&&v.width.value!=""){o=1;k=k.replace(/align[^ "']+\s?/gi,"")}p=g.dom.getParent(e,"a");h=g.dom.getParent(e,"p");n=g.dom.getParent(e,"dl");r=g.dom.getParent(e,"div");tinyMCEPopup.execCommand("mceBeginUndoLevel");if(v.width.value!=e.width||v.height.value!=e.height){k=k.replace(/size-[^ "']+/,"")}g.dom.setAttribs(e,{src:v.img_src.value,title:v.img_title.value,alt:v.img_alt.value,width:v.width.value,height:v.height.value,style:v.img_style.value,"class":k});if(v.link_href.value){if(p==null){if(!v.link_href.value.match(/https?:\/\//i)){v.link_href.value=tinyMCEPopup.editor.documentBaseURI.toAbsolute(v.link_href.value)}if(tinymce.isWebKit&&g.dom.hasClass(e,"aligncenter")){g.dom.removeClass(e,"aligncenter");d=1}tinyMCEPopup.execCommand("CreateLink",false,"#mce_temp_url#",{skip_undo:1});if(d){g.dom.addClass(e,"aligncenter")}tinymce.each(g.dom.select("a"),function(b){if(g.dom.getAttrib(b,"href")=="#mce_temp_url#"){g.dom.setAttribs(b,{href:v.link_href.value,title:v.link_title.value,rel:v.link_rel.value,target:(v.link_target.checked==true)?"_blank":"","class":v.link_classes.value,style:v.link_style.value})}})}else{g.dom.setAttribs(p,{href:v.link_href.value,title:v.link_title.value,rel:v.link_rel.value,target:(v.link_target.checked==true)?"_blank":"","class":v.link_classes.value,style:v.link_style.value})}}if(o){a=10+parseInt(v.width.value);z=(m.align=="aligncenter")?"mceTemp mceIEcenter":"mceTemp";if(n){g.dom.setAttribs(n,{"class":"wp-caption "+m.align,style:"width: "+a+"px;"});if(r){g.dom.setAttrib(r,"class",z)}if((i=g.dom.getParent(e,"dt"))&&(s=i.nextSibling)&&g.dom.hasClass(s,"wp-caption-dd")){g.dom.setHTML(s,v.img_cap_text.value)}}else{if((q=v.img_classes.value.match(/wp-image-([0-9]{1,6})/))&&q[1]){u="attachment_"+q[1]}if(v.link_href.value&&(w=g.dom.getParent(e,"a"))){if(w.childNodes.length==1){l=g.dom.getOuterHTML(w)}else{l=g.dom.getOuterHTML(w);l=l.match(/]+>/i);l=l+g.dom.getOuterHTML(e)+""}}else{l=g.dom.getOuterHTML(e)}l='
'+l+'
'+v.img_cap_text.value+"
";j=g.dom.create("div",{"class":z},l);if(h){h.parentNode.insertBefore(j,h);if(h.childNodes.length==1){g.dom.remove(h)}else{if(w&&w.childNodes.length==1){g.dom.remove(w)}else{g.dom.remove(e)}}}else{if(c=g.dom.getParent(e,"TD,TH,LI")){c.appendChild(j);if(w&&w.childNodes.length==1){g.dom.remove(w)}else{g.dom.remove(e)}}}}}else{if(n&&r){if(v.link_href.value&&(y=g.dom.getParent(e,"a"))){l=g.dom.getOuterHTML(y)}else{l=g.dom.getOuterHTML(e)}h=g.dom.create("p",{},l);r.parentNode.insertBefore(h,r);g.dom.remove(r)}}if(v.img_classes.value.indexOf("aligncenter")!=-1){if(h&&(!h.style||h.style.textAlign!="center")){g.dom.setStyle(h,"textAlign","center")}}else{if(h&&h.style&&h.style.textAlign=="center"){g.dom.setStyle(h,"textAlign","")}}if(!v.link_href.value&&p){x=g.selection.getBookmark();g.dom.remove(p,1);g.selection.moveToBookmark(x)}tinyMCEPopup.execCommand("mceEndUndoLevel");g.execCommand("mceRepaint");tinyMCEPopup.close()},updateStyle:function(a){var e=tinyMCEPopup.dom,c,d=document.forms[0],b=e.create("img",{style:d.img_style.value});if(tinyMCEPopup.editor.settings.inline_styles){if(a=="align"){e.setStyle(b,"float","");e.setStyle(b,"vertical-align","");c=d.align.value;if(c){if(c=="left"||c=="right"){e.setStyle(b,"float",c)}else{b.style.verticalAlign=c}}}if(a=="border"){e.setStyle(b,"border","");c=d.border.value;if(c||c=="0"){if(c=="0"){b.style.border="0"}else{b.style.border=c+"px solid black"}}}if(a=="hspace"){e.setStyle(b,"marginLeft","");e.setStyle(b,"marginRight","");c=d.hspace.value;if(c){b.style.marginLeft=c+"px";b.style.marginRight=c+"px"}}if(a=="vspace"){e.setStyle(b,"marginTop","");e.setStyle(b,"marginBottom","");c=d.vspace.value;if(c){b.style.marginTop=c+"px";b.style.marginBottom=c+"px"}}d.img_style.value=e.serializeStyle(e.parseStyle(b.style.cssText));this.demoSetStyle()}},checkVal:function(a){if(a.value==""){if(a.id=="img_src"){a.value=this.I("img_demo").src||this.preloadImg.src}}},resetImageData:function(){var a=document.forms[0];a.width.value=a.height.value=""},updateImageData:function(){var d=document.forms[0],b=wpImage,a=d.width.value,c=d.height.value;if(!a&&c){a=d.width.value=b.width=Math.round(b.preloadImg.width/(b.preloadImg.height/c))}else{if(a&&!c){c=d.height.value=b.height=Math.round(b.preloadImg.height/(b.preloadImg.width/a))}}if(!a){d.width.value=b.width=b.preloadImg.width}if(!c){d.height.value=b.height=b.preloadImg.height}b.showSizeSet();b.demoSetSize();if(d.img_style.value){b.demoSetStyle()}},getImageData:function(){var a=wpImage,b=document.forms[0];a.preloadImg=new Image();a.preloadImg.onload=a.updateImageData;a.preloadImg.onerror=a.resetImageData;a.preloadImg.src=tinyMCEPopup.editor.documentBaseURI.toAbsolute(b.img_src.value)}};window.onload=function(){wpImage.init()};wpImage.preInit();