var wpLink;!function(o){var t,e,i,s={},n={};wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){s.dialog=o("#wp-link"),s.submit=o("#wp-link-submit"),s.url=o("#url-field"),s.nonce=o("#_ajax_linking_nonce"),s.title=o("#link-title-field"),s.openInNewTab=o("#link-target-checkbox"),s.search=o("#search-field"),n.search=new e(o("#search-results")),n.recent=new e(o("#most-recent-results")),n.elements=o(".query-results",s.dialog),s.dialog.keydown(wpLink.keydown),s.dialog.keyup(wpLink.keyup),s.submit.click(function(e){e.preventDefault(),wpLink.update()}),o("#wp-link-cancel").click(function(e){e.preventDefault(),wpLink.close()}),o("#internal-toggle").click(wpLink.toggleInternalLinking),n.elements.bind("river-select",wpLink.updateFields),s.search.keyup(wpLink.searchInternalLinks),s.dialog.bind("wpdialogrefresh",wpLink.refresh),s.dialog.bind("wpdialogbeforeopen",wpLink.beforeOpen),s.dialog.bind("wpdialogclose",wpLink.onClose)},beforeOpen:function(){wpLink.range=null,!wpLink.isMCE()&&document.selection&&(wpLink.textarea.focus(),wpLink.range=document.selection.createRange())},open:function(){wpActiveEditor&&(this.textarea=o("#"+wpActiveEditor).get(0),s.dialog.data("wpdialog")||s.dialog.wpdialog({title:wpLinkL10n.title,width:480,height:"auto",modal:!0,dialogClass:"wp-dialog"}),s.dialog.wpdialog("open"))},isMCE:function(){return tinyMCEPopup&&(t=tinyMCEPopup.editor)&&!t.isHidden()},refresh:function(){n.search.refresh(),n.recent.refresh(),wpLink.isMCE()?wpLink.mceRefresh():wpLink.setDefaultValues(),s.url.focus()[0].select(),n.recent.ul.children().length||n.recent.ajax()},mceRefresh:function(){var e;t=tinyMCEPopup.editor,tinyMCEPopup.restoreSelection(),(e=t.dom.getParent(t.selection.getNode(),"A"))?(s.url.val(t.dom.getAttrib(e,"href")),s.title.val(t.dom.getAttrib(e,"title")),s.openInNewTab.prop("checked","_blank"==t.dom.getAttrib(e,"target")),s.submit.val(wpLinkL10n.update)):wpLink.setDefaultValues()},close:function(){wpLink.isMCE()?tinyMCEPopup.close():s.dialog.wpdialog("close")},onClose:function(){wpLink.isMCE()||(wpLink.textarea.focus(),wpLink.range&&(wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select()))},getAttrs:function(){return{href:s.url.val(),title:s.title.val(),target:s.openInNewTab.prop("checked")?"_blank":""}},update:function(){wpLink.isMCE()?wpLink.mceUpdate():wpLink.htmlUpdate()},htmlUpdate:function(){var e,t,i,n,l=wpLink.textarea;l&&(i=wpLink.getAttrs(),(n=document.createElement("a")).href=i.href,"javascript:"!==n.protocol&&"data:"!==n.protocol||(i.href=""),i.href&&"http://"!=i.href&&(e='",document.selection&&wpLink.range?(l.focus(),wpLink.range.text=e+wpLink.range.text+"",wpLink.range.moveToBookmark(wpLink.range.getBookmark()),wpLink.range.select(),wpLink.range=null):void 0!==l.selectionStart&&(t=l.selectionStart,n=l.selectionEnd,i=t+(e=e+l.value.substring(t,n)+"").length,t==n&&(i-="".length),l.value=l.value.substring(0,t)+e+l.value.substring(n,l.value.length),l.selectionStart=l.selectionEnd=i),wpLink.close(),l.focus()))},mceUpdate:function(){var t,i=tinyMCEPopup.editor,n=wpLink.getAttrs();tinyMCEPopup.restoreSelection(),t=i.dom.getParent(i.selection.getNode(),"A");var e=document.createElement("a");e.href=n.href,"javascript:"!==e.protocol&&"data:"!==e.protocol||(n.href=""),n.href&&"http://"!=n.href?(null==t?(i.getDoc().execCommand("unlink",!1,null),tinyMCEPopup.execCommand("mceInsertLink",!1,"#mce_temp_url#",{skip_undo:1}),tinymce.each(i.dom.select("a"),function(e){"#mce_temp_url#"==i.dom.getAttrib(e,"href")&&(t=e,i.dom.setAttribs(t,n))}),tinymce.isWebKit&&"#mce_temp_url#"==o(t).text()&&(i.dom.remove(t),t=null)):i.dom.setAttribs(t,n),!t||1==t.childNodes.length&&"IMG"==t.firstChild.nodeName||(i.selection.select(t),i.selection.collapse(0),tinyMCEPopup.storeSelection()),i.execCommand("mceEndUndoLevel"),wpLink.close(),i.focus()):t&&(e=i.selection.getBookmark(),i.dom.remove(t,1),i.selection.moveToBookmark(e),tinyMCEPopup.execCommand("mceEndUndoLevel"),wpLink.close())},updateFields:function(e,t,i){s.url.val(t.children(".item-permalink").val()),s.title.val(t.hasClass("no-title")?"":t.children(".item-title").text()),i&&"click"==i.type&&s.url.focus()},setDefaultValues:function(){s.url.val("http://"),s.title.val(""),s.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var e,t=o(this),i=t.val();2':"",n+='',n+='',n+=this.title||wpLinkL10n.noTitle,n+=''+this.info+"",l=!l}):t&&(n+=''+wpLinkL10n.noMatchesFound+""),this.ul[t?"html":"append"](n)},maybeLoad:function(){var i=this,n=this.element,e=n.scrollTop()+n.height();!this.query.ready()||e