var WPNavMenuHandler=function(){var i=jQuery,a=false,k=null,h,d,n,j,m={},o=function(q,u,r,t){if(q&&q[0]){var s=i.parseJSON(q[0]);if(s.post_title){if(s.ID&&s.post_type){m[s.post_title]={ID:s.ID,object_type:s.post_type}}return s.post_title}}},p=function(q,u,r,t){if(q&&q[0]){var s=i.parseJSON(q[0]);if(s.post_title){return s.post_title}}},b=function(w,v){if(!w){return false}v=v||document;var r=["menu-item-db-id","menu-item-object-id","menu-item-object","menu-item-parent-id","menu-item-position","menu-item-type","menu-item-append","menu-item-title","menu-item-url","menu-item-description","menu-item-attr-title","menu-item-target","menu-item-classes","menu-item-xfn"],q={},s=v.getElementsByTagName("input"),u=s.length,t,x=document.getElementById("nav-menu-meta-object-id").value;while(u--){t=r.length;while(t--){if(s[u]&&s[u].name&&"menu-item["+w+"]["+r[t]+"]"==s[u].name){q[r[t]]=s[u].value}}}return q},c=function(){var u=this.getElementsByTagName("input"),r=u.length,q,t,s;while(r--){if(-1!=u[r].name.indexOf("menu-item-parent-id["+parseInt(this.id.replace("menu-item-",""),10)+"]")){if(!this.parentNode.className||-1==this.parentNode.className.indexOf("sub-menu")){u[r].value=0}else{if("LI"==this.parentNode.parentNode.nodeName&&-1!=this.parentNode.parentNode.id.indexOf("menu-item-")){t=this.parentNode.parentNode;s=t.getElementsByTagName("input");q=s.length;while(q--){if(s[q].name&&-1!=s[q].name.indexOf("menu-item-object-id["+parseInt(t.id.replace("menu-item-",""),10)+"]")){u[r].value=parseInt(s[q].value,10);break}}}}break}}},e=function(r,t){var s=document.getElementById("nav-menu-meta"),q;while(r.parentNode&&(!r.className||-1==r.className.indexOf(t))&&r.parentNode!=s){r=r.parentNode}return r},f=function(q){var r=this;i(q).droppable({accept:".menu li",tolerance:"pointer",drop:function(t,s){r.eventOnDrop(s.draggable[0],this,s,t)},over:function(t,s){r.eventOnDragOver(s.draggable[0],this,s,t)},out:function(t,s){r.eventOnDragOut(s.draggable[0],this,s,t)}})},l,g=function(t){if(!t){return}var r=document.getElementById(t.id+"-dummy-list-item"),q=t.getElementsByTagName("li"),s=q.length;if(!r){r=document.createElement("li");r.id=t.id+"-dummy-list-item";t.appendChild(r);this.setupListItemDragAndDrop(r)}while(s--){this.setupListItemDragAndDrop(q[s])}};return{init:function(){l=document.getElementById("menu-to-edit");this.attachMenuEditListeners();this.attachMenuMetaListeners(document.getElementById("nav-menu-meta"));this.attachTabsPanelListeners();g.call(this,l);postboxes.add_postbox_toggles("nav-menus")},attachMenuEditListeners:function(){var q=this;i("#update-nav-menu").bind("click",function(r){if(r.target&&r.target.className){if(-1!=r.target.className.indexOf("item-edit")){return q.eventOnClickEditLink(r.target)}else{if(-1!=r.target.className.indexOf("menu-delete")){return q.eventOnClickMenuDelete(r.target)}else{if(-1!=r.target.className.indexOf("item-delete")){return q.eventOnClickMenuItemDelete(r.target)}}}}})},attachMenuMetaListeners:function(q){if(!q){return}var r=this;h=document.getElementById("custom-menu-item-name");d=document.getElementById("custom-menu-item-url");if(h){n="undefined"!=typeof h.defaultValue?h.defaultValue:h.getAttribute("value");j="undefined"!=typeof d.defaultValue?d.defaultValue:d.getAttribute("value");i(h).bind("focus",function(s){this.value=n==this.value?"":this.value});i(h).bind("blur",function(s){this.value=""==this.value?n:this.value})}i("input.quick-search").each(function(s,t){r.setupQuickSearchEventListeners(t)});i(q).bind("submit",function(s){return r.eventSubmitMetaForm.call(r,this,s)})},attachTabsPanelListeners:function(){i("#menu-settings-column").bind("click",function(v){if(v.target&&v.target.className&&-1!=v.target.className.indexOf("menu-tab-link")){var w,r=/#(.*)$/.exec(v.target.href),u,x=e(v.target,"inside"),q=x?x.getElementsByTagName("input"):[],s=q.length;while(s--){q[s].checked=false}i(".tabs-panel",x).each(function(){if(this.className){this.className=this.className.replace("tabs-panel-active","tabs-panel-inactive")}});i(".tabs",x).each(function(){this.className=this.className.replace("tabs","")});v.target.parentNode.className+=" tabs";if(r&&r[1]){w=document.getElementById(r[1]);if(w){w.className=w.className.replace("tabs-panel-inactive","tabs-panel-active")}}return false}else{if(v.target&&v.target.className&&-1!=v.target.className.indexOf("select-all")){var t=/#(.*)$/.exec(v.target.href);if(t&&t[1]){i("#"+t[1]+" .tabs-panel-active input[type=checkbox]").attr("checked","checked");return false}}}})},setupListItemDragAndDrop:function(s){var q=s.getElementsByTagName("dl"),t=this.makeListItemDropzone(s),r=q.length;f.call(this,t);this.makeListItemDraggable(s);while(r--){f.call(this,q[r])}},setupQuickSearchEventListeners:function(q){var r=this;i(q).autocomplete(ajaxurl+"?action=menu-quick-search&type="+q.name,{delay:500,formatItem:o,formatResult:p,minchars:2,multiple:false}).bind("blur",function(u){var s=m[this.value],t=this;if(s){i.post(ajaxurl+"?action=menu-quick-search&type=get-post-item&response-format=markup",s,function(v){r.processQuickSearchQueryResponse.call(r,v,s);m[t.value]=false})}})},eventOnClickEditLink:function(q){var s,r=/#(.*)$/.exec(q.href);if(r&&r[1]){s=document.getElementById(r[1]);if(s){if(-1!=s.className.indexOf("menu-item-edit-inactive")){s.className=s.className.replace("menu-item-edit-inactive","menu-item-edit-active")}else{s.className=s.className.replace("menu-item-edit-active","menu-item-edit-inactive")}return false}}},eventOnClickMenuDelete:function(q){if(confirm(navMenuL10n.warnDeleteMenu)){return true}else{return false}},eventOnClickMenuItemDelete:function(q){var t,s,r=this;if(confirm(navMenuL10n.warnDeleteMenuItem)){s=/_wpnonce=([a-zA-Z0-9]*)$/.exec(q.href);if(s&&s[1]){t=parseInt(q.id.replace("delete-",""),10);i.post(ajaxurl,{action:"delete-menu-item","menu-item":t,_wpnonce:s[1]},function(u){if("1"==u){r.removeMenuItem(document.getElementById("menu-item-"+t))}});return false}return true}else{return false}},eventOnDragOver:function(q,r){a=true;k=r;r.className+=" sortable-placeholder"},eventOnDragOut:function(q,r){a=false;(function(s){setTimeout(function(){if(s!=k||(!a&&s.className&&-1!=s.className.indexOf("sortable-placeholder"))){s.className=s.className.replace(/sortable-placeholder/g,"")}},800)})(r)},eventOnDrop:function(t,w){var u=!!(-1==w.className.indexOf("dropzone")),r=w.parentNode.getElementsByTagName("ul"),v=false,s=r.length,q;a=false;w.className=w.className.replace(/sortable-placeholder/g,"");if(u){while(s--){if(r[s]&&1!=r[s].className.indexOf("sub-menu")){v=true;q=r[s]}}if(!v){q=document.createElement("ul");q.className="sub-menu";w.parentNode.appendChild(q)}q.appendChild(t)}else{w.parentNode.parentNode.insertBefore(t,w.parentNode)}this.recalculateSortOrder(l);c.call(t)},eventSubmitMetaForm:function(r,y){var v,w=r.getElementsByTagName("input"),u=w.length,t,A,q,x,s={},z=function(){},B=new RegExp("menu-item\\[([^\\]]*)");that=this;s.action="";while(u--){if(w[u].name&&-1!=w[u].name.indexOf("menu-item-object-id")&&w[u].checked||("undefined"!=typeof w[u].id&&"custom-menu-item-url"==w[u].id&&""!=w[u].value&&"http://"!=w[u].value)){s.action="add-menu-item";z=that.processAddMenuItemResponse;x=B.exec(w[u].name);q="undefined"==typeof x[1]?0:parseInt(x[1],10);A=b(q);for(t in A){s["menu-item["+q+"]["+t+"]"]=A[t]}v=e(w[u],"inside");w[u].checked=false}else{if(""==s.action&&""!=w[u].value&&w[u].className&&-1!=w[u].className.search(/quick-search\b[^-]/)){v=e(w[u],"inside");s.action="menu-quick-search";s.q=w[u].value;s["response-format"]="markup";s.type=w[u].name;z=that.processQuickSearchQueryResponse}}}if(v){v.className=v.className+" processing",s.menu=r.elements.menu.value}s["menu-settings-column-nonce"]=r.elements["menu-settings-column-nonce"].value;i.post(ajaxurl,s,function(C){z.call(that,C,s);v.className=v.className.replace(/processing/g,"")});return false},makeListItemDraggable:function(q){i(q).draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100})},makeListItemDropzone:function(s){if(!s){return false}var r=s.getElementsByTagName("div"),q=r.length,t=document.createElement("div");while(q--){if(r[q].className&&-1!=r[q].className.indexOf("dropzone")&&(s==r[q].parentNode)){return r[q]}}t.className="dropzone";s.insertBefore(t,s.firstChild);return t},processAddMenuItemResponse:function(q,v){if(!v){v={}}var w,r=document.getElementById(l.id+"-dummy-list-item"),t,s,u=document.createElement("ul");u.innerHTML=q;s=u.getElementsByTagName("li");t=s.length;while(t--){this.setupListItemDragAndDrop(s[t]);if(r){l.insertBefore(s[t],r)}else{l.appendChild(s[t])}}this.recalculateSortOrder(l);if(h&&d){h.value=n;d.value=j}},processQuickSearchQueryResponse:function(u,z){if(!z){z={}}var r=document.createElement("ul"),q=document.getElementById("nav-menu-meta"),v,y,s,A,w,x=new RegExp("menu-item\\[([^\\]]*)"),t;s=x.exec(u);if(s&&s[1]){w=s[1];while(q.elements["menu-item["+w+"][menu-item-type]"]){w--}if(w!=s[1]){u=u.replace(new RegExp("menu-item\\["+s[1]+"\\]","g"),"menu-item["+w+"]")}}r.innerHTML=u;y=r.getElementsByTagName("li");if(y[0]&&z.object_type){t=document.getElementById(z.object_type+"-search-checklist");if(t){t.innerHTML="";t.appendChild(y[0])}}else{if(z.type){s=/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*)/.exec(z.type);if(s&&s[2]){t=document.getElementById(s[2]+"-search-checklist");if(t){t.innerHTML="";v=y.length;if(!v){A=document.createElement("li");A.appendChild(document.createTextNode(navMenuL10n.noResultsFound));t.appendChild(A)}while(v--){t.appendChild(y[v])}}}}}},recalculateSortOrder:function(s){var t=s.getElementsByTagName("input"),r,q=0;for(r=0;r