var wpNavMenu;(function(b){var a=wpNavMenu={options:{menuItemDepthPerLevel:30,globalMaxDepth:11},menuList:undefined,targetList:undefined,autoCompleteData:{},init:function(){a.menuList=b("#menu-to-edit");a.targetList=a.menuList;this.jQueryExtensions();this.attachMenuEditListeners();this.setupInputWithDefaultTitle();this.attachAddMenuItemListeners();this.attachQuickSearchListeners();this.attachTabsPanelListeners();this.attachHomeLinkListener();if(a.menuList.length){this.initSortables()}this.initToggles();this.initTabManager()},jQueryExtensions:function(){b.fn.extend({menuItemDepth:function(){return a.pxToDepth(this.eq(0).css("margin-left").slice(0,-2))},updateDepthClass:function(d,c){return this.each(function(){var e=b(this);c=c||e.menuItemDepth();b(this).removeClass("menu-item-depth-"+c).addClass("menu-item-depth-"+d)})},shiftDepthClass:function(c){return this.each(function(){var d=b(this),e=d.menuItemDepth();b(this).removeClass("menu-item-depth-"+e).addClass("menu-item-depth-"+(e+c))})},childMenuItems:function(){var c=b();this.each(function(){var d=b(this),f=d.menuItemDepth(),e=d.next();while(e.length&&e.menuItemDepth()>f){c=c.add(e);e=e.next()}});return c},updateParentMenuItemDBId:function(){return this.each(function(){var e=b(this),c=e.find(".menu-item-data-parent-id"),f=e.menuItemDepth(),d=e.prev();if(f==0){c.val(0)}else{while(d.menuItemDepth()!=f-1){d=d.prev()}c.val(d.find(".menu-item-data-db-id").val())}})},hideAdvancedMenuItemFields:function(){return this.each(function(){var c=b(this);b(".hide-column-tog").not(":checked").each(function(){c.find(".field-"+b(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(c){return this.each(function(){var e=b(this),d={},g=e.find(".tabs-panel-active .categorychecklist li input:checked"),f=new RegExp("menu-item\\[([^\\]]*)");c=c||a.addMenuItemToBottom;if(!g.length){return false}e.find("img.waiting").show();b(g).each(function(){var h=f.exec(b(this).attr("name")),i="undefined"==typeof h[1]?0:parseInt(h[1],10);d[i]=a.getListDataFromID(i)});a.addItemToMenu(d,c,function(){g.removeAttr("checked");e.find("img.waiting").hide()})})}})},initToggles:function(){postboxes.add_postbox_toggles("nav-menus");columns.useCheckboxesForHidden();columns.checked=function(c){b(".field-"+c).removeClass("hidden-field")};columns.unchecked=function(c){b(".field-"+c).addClass("hidden-field")};a.menuList.hideAdvancedMenuItemFields()},initSortables:function(){var m=0,l,j,e,h,n,k,o,d,g,i=a.menuList.offset().left;a.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",start:function(w,v){var p,t,s,q,r,u;g=v.item.children(".menu-item-transport");l=v.item.menuItemDepth();f(v,l);s=(v.item.next()[0]==v.placeholder[0])?v.item.next():v.item;q=s.childMenuItems();g.append(q);p=g.outerHeight();p+=(p>0)?(v.placeholder.css("margin-top").slice(0,-2)*1):0;p+=v.helper.outerHeight();d=p;p-=2;v.placeholder.height(p);r=l;q.each(function(){var x=b(this).menuItemDepth();r=(x>r)?x:r});t=v.helper.find(".menu-item-handle").outerWidth();t+=a.depthToPx(r-l);t-=2;v.placeholder.width(t);u=v.placeholder.next();u.css("margin-top",d+"px");v.placeholder.detach();b(this).sortable("refresh");v.item.after(v.placeholder);u.css("margin-top",0);c(v)},stop:function(s,r){var q,p=m-l;q=g.children().insertAfter(r.item);if(p!=0){r.item.updateDepthClass(m);q.shiftDepthClass(p)}r.item.updateParentMenuItemDBId();a.recalculateMenuItemPositions()},change:function(q,p){if(!p.placeholder.parent().hasClass("menu")){(h.length)?h.after(p.placeholder):a.menuList.prepend(p.placeholder)}c(p)},sort:function(q,p){var s=p.helper.offset(),r=a.pxToDepth(s.left-i);if(r>e||s.topo){n.after(p.placeholder);c(p);b(this).sortable("refreshPositions")}}});function c(p){var q;h=p.placeholder.prev();n=p.placeholder.next();if(h[0]==p.item[0]){h=h.prev()}if(n[0]==p.item[0]){n=n.next()}k=(h.length)?h.offset().top+h.height():0;o=(n.length)?n.offset().top+n.height()/3:0;j=(n.length)?n.menuItemDepth():0;if(h.length){e=((q=h.menuItemDepth()+1)>a.options.globalMaxDepth)?a.options.globalMaxDepth:q}else{e=0}}function f(p,q){p.placeholder.updateDepthClass(q,m);m=q}},attachMenuEditListeners:function(){var c=this;b("#update-nav-menu").bind("click",function(d){if(d.target&&d.target.className){if(-1!=d.target.className.indexOf("item-edit")){return c.eventOnClickEditLink(d.target)}else{if(-1!=d.target.className.indexOf("menu-delete")){return c.eventOnClickMenuDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-delete")){return c.eventOnClickMenuItemDelete(d.target)}else{if(-1!=d.target.className.indexOf("item-close")){return c.eventOnClickCloseLink(d.target)}}}}}})},setupInputWithDefaultTitle:function(){var c="input-with-default-title";b("."+c).each(function(){var f=b(this),e=f.attr("title"),d=f.val();f.data(c,e);if(""==d){f.val(e)}else{if(e==d){return}else{f.removeClass(c)}}}).focus(function(){var d=b(this);if(d.val()==d.data(c)){d.val("").removeClass(c)}}).blur(function(){var d=b(this);if(""==d.val()){d.addClass(c).val(d.data(c))}})},attachAddMenuItemListeners:function(){var c=b("#nav-menu-meta");c.find(".add-to-menu input").click(function(){b(this).trigger("wp-add-menu-item",[a.addMenuItemToBottom]);return false});c.find(".customlinkdiv").bind("wp-add-menu-item",function(f,d){a.addCustomLink(d)});c.find(".posttypediv, .taxonomydiv").bind("wp-add-menu-item",function(f,d){b(this).addSelectedToMenu(d)})},attachQuickSearchListeners:function(){var d=this,c=b("#nav-menu-meta");b("input.quick-search").each(function(e,f){d.setupQuickSearchEventListeners(f)});c.find(".quick-search-submit").click(function(){b(this).trigger("wp-quick-search");return false});c.find(".inside").children().bind("wp-quick-search",function(){d.quickSearch(b(this).attr("id"))})},quickSearch:function(j){var e=b("#"+j+" .quick-search").attr("name"),g=b("#"+j+" .quick-search").val(),i=b("#menu").val(),d=b("#menu-settings-column-nonce").val(),h={},f=this,c=function(){};c=f.processQuickSearchQueryResponse;h={action:"menu-quick-search","response-format":"markup",menu:i,"menu-settings-column-nonce":d,q:g,type:e};b.post(ajaxurl,h,function(k){c.call(f,k,h)})},addCustomLink:function(c){var e=b("#custom-menu-item-url").val(),d=b("#custom-menu-item-name").val();c=c||a.addMenuItemToBottom;if(""==e||"http://"==e){return false}b(".customlinkdiv img.waiting").show();this.addLinkToMenu(e,d,c,function(){b(".customlinkdiv img.waiting").hide();b("#custom-menu-item-name").val("").blur();b("#custom-menu-item-url").val("http://")})},addLinkToMenu:function(e,d,c,f){c=c||a.addMenuItemToBottom;f=f||function(){};a.addItemToMenu({"-1":{"menu-item-type":"custom","menu-item-url":e,"menu-item-title":d}},c,f)},addItemToMenu:function(e,c,g){var f=b("#menu").val(),d=b("#menu-settings-column-nonce").val();c=c||function(){};g=g||function(){};params={action:"add-menu-item",menu:f,"menu-settings-column-nonce":d,"menu-item":e};b.post(ajaxurl,params,function(h){c(h,params);g()})},addMenuItemToBottom:function(c,d){b(c).hideAdvancedMenuItemFields().appendTo(a.targetList)},addMenuItemToTop:function(c,d){b(c).hideAdvancedMenuItemFields().prependTo(a.targetList)},attachHomeLinkListener:function(){b(".add-home-link",".customlinkdiv").click(function(c){a.addLinkToMenu(navMenuL10n.homeurl,navMenuL10n.home,a.addMenuItemToTop,a.recalculateMenuItemPositions);return false})},attachTabsPanelListeners:function(){b("#menu-settings-column").bind("click",function(j){var h,k,d,l,c,g,f;if(j.target&&j.target.className&&-1!=j.target.className.indexOf("nav-tab-link")){d=/#(.*)$/.exec(j.target.href);l=b(j.target).parents(".inside").first()[0];c=l?l.getElementsByTagName("input"):[];g=c.length;while(g--){c[g].checked=false}b(".tabs-panel",l).each(function(){if(this.className){this.className=this.className.replace("tabs-panel-active","tabs-panel-inactive")}});b(".tabs",l).each(function(){this.className=this.className.replace("tabs","")});j.target.parentNode.className+=" tabs";if(d&&d[1]){k=document.getElementById(d[1]);if(k){k.className=k.className.replace("tabs-panel-inactive","tabs-panel-active")}}return false}else{if(j.target&&j.target.className&&-1!=j.target.className.indexOf("select-all")){h=/#(.*)$/.exec(j.target.href);if(h&&h[1]){f=b("#"+h[1]+" .tabs-panel-active .menu-item-title input");if(f.length===f.filter(":checked").length){f.removeAttr("checked")}else{f.attr("checked","checked")}return false}}}})},initTabManager:function(){var h=b(".nav-tabs-wrapper"),i=h.children(".nav-tabs"),g=i.children(".nav-tab-active"),l=i.children(".nav-tab"),e=0,m,f,k,d,j=false;function c(){f=h.offset().left;m=f+h.width();g.makeTabVisible()}b.fn.extend({makeTabVisible:function(){var o=this.eq(0),p,n;if(!o.length){return}p=o.offset().left;n=p+o.outerWidth();if(n>m){i.animate({"margin-left":"+="+(m-n)+"px"},"fast")}else{if(p=f)?true:false}});l.each(function(){e+=b(this).outerWidth(true)});if(e<=h.width()-i.css("padding-left").slice(0,-2)-i.css("padding-right").slice(0,-2)){return}i.css({"margin-right":(-1*e)+"px",padding:0});k=b('');d=b('');h.wrap('