AJS.menuShowCount=0;jQuery.fn.ajsMenu=function(i){i=i||{};var c=jQuery;var g=null;var f=function(j){if(typeof AJS.dropDownTimer!="undefined"&&AJS.dropDownHider){clearTimeout(AJS.dropDownTimer);delete AJS.dropDownTimer;AJS.dropDownHider();AJS.dropDownHider=null}};var d=function(){return c(".ajs-menu-bar.menu-bar-open").length>0};var h=function(j){c(j).closest(".ajs-menu-bar").find(".ajs-drop-down").each(function(k){this.hide()})};var e=function(j){return c(j).closest(".ajs-menu-bar").hasClass("menu-bar-open")};var b=function(j){c(j).closest(".ajs-menu-bar").addClass("menu-bar-open")};var a=function(j){c(j).closest(".ajs-menu-bar").removeClass("menu-bar-open")};c(".ajs-button",this).each(function(){c(this).mouseover(function(){var k=this;var m=e(k);h(k);if(m){var l=c(document);var j=function(){a(k);return false};l.unbind("click.menu");setTimeout(function(){l.one("click.menu",j)},1);b(k)}})});c(".ajs-menu-item",this).each(function(){var l=this,j=c(this),p=c(".ajs-drop-down",l);if(!p.length){return}p=p[0];p.hidden=true;p.focused=-1;p.hide=function(){if(!this.hidden){j.toggleClass("opened");var t=c(l.parentNode);if(t.find(".opened").length==0){a(l)}var s=c("a",this);c(this).toggleClass("assistive");this.hidden=true;c(document).unbind("click",this.fhide).unbind("keydown",this.fmovefocus).unbind("keypress",this.blocker);if(this.focused+1){c(s[this.focused]).removeClass("active")}this.focused=-1}};p.show=function(){if(typeof this.hidden=="undefined"||this.hidden){var s=this,w=c(this);w.toggleClass("assistive");j.toggleClass("opened");b(l);this.hidden=false;this.timer=setTimeout(function(){c(document).click(s.fhide)},1);c(document).keydown(s.fmovefocus).keypress(s.blocker);var t=c("a",s);t.each(function(y){var x=this.parentNode.parentNode;c(this).hover(function(z){if(x.focused+1){c(t[x.focused].parentNode).removeClass("active")}c(this.parentNode).addClass("active");x.focused=y},function(z){if(x.focused+1){c(t[x.focused].parentNode).removeClass("active")}x.focused=-1})});var v=(window.pageYOffset||document.documentElement.scrollTop);var u=v+c(window).height();w.removeClass("above");if(!i.isFixedPosition){if(w.offset().top+w.height()>u){w.addClass("above");if(w.offset().top<v){w.removeClass("above")}}}}};p.isMenuBarOpened=function(){return e(p)};p.closeOthers=function(){h(p)};p.fmovefocus=function(s){p.movefocus(s)};p.fhide=function(s){p.hide(s);return AJS.$(s.target).closest(".ajs-drop-down").length>0};p.blocker=function(s){var t=s.which;if(t==40||t==38){return false}};p.movefocus=function(u){var x=u.which,t=this.getElementsByTagName("a"),w=this.focused,s=(x==9),v;do{switch(x){case 40:case 9:if(u.shiftKey){this.focused--}else{this.focused++}break;case 38:this.focused--;break;case 27:this.hide();return false;default:return true}v=(this.focused<0||this.focused>t.length-1)}while(!v&&c(t[this.focused].parentNode).hasClass("assistive"));if(s&&v){if(w!=-1){c(t[w].parentNode).removeClass("active")}this.focused=-1;this.hide();return false}else{if(!s){if(this.focused<0){this.focused=t.length-1}else{if(this.focused>t.length-1){this.focused=0}}}}if(w>=0){c(t[w].parentNode).removeClass("active")}t[this.focused].focus();c(t[this.focused].parentNode).addClass("active");u.stopPropagation();u.preventDefault();return false};p.show();clearTimeout(p.timer);var m=c(p),k=m.offset();p.hide();var o=c(".trigger",l);if(o.length){var q=function(){clearTimeout(AJS.dropDownTimer);delete AJS.dropDownTimer;AJS.dropDownHider();AJS.dropDownHider=null;p.show()};var r=function(t){var s=typeof AJS.dropDownTimer!="undefined";g=p;if(s){q()}else{AJS.dropDownShower=function(){p.show();delete AJS.dropDownShowerTimer};AJS.dropDownShowerTimer=setTimeout(AJS.dropDownShower,t)}};var n=function(s){var t=typeof AJS.dropDownShowerTimer!="undefined";if(t){clearTimeout(AJS.dropDownShowerTimer);delete AJS.dropDownShowerTimer}if(typeof AJS.dropDownTimer!="undefined"){clearTimeout(AJS.dropDownTimer);delete AJS.dropDownHider}AJS.dropDownHider=function(){p.hide();delete AJS.dropDownTimer};AJS.dropDownTimer=setTimeout(AJS.dropDownHider,s)};j.mouseover(function(){if(p.isMenuBarOpened()){if(p.hidden){h(p);p.show()}}else{j.addClass("hover")}});j.mouseout(function(){if(!p.isMenuBarOpened()){j.removeClass("hover")}});o.click(function(){if(p.hidden){o.parent("li").removeClass("hover");var s=d();p.show();return s}else{p.hide();o.parent("li").addClass("hover");return false}})}})};AJS.toInit(function(c){c("#view-user-history-link").click(function(j){window.open(this.href,(this.id+"-popupwindow").replace(/-/g,"_"),"width=600, height=400, scrollbars, resizable");j.preventDefault();return false});var d=function(j,k){var l=c("#ajax-error");if(l.length==0){c("#com-atlassian-confluence").prepend("<div id='ajax-error'></div>");l=c("#ajax-error")}l.append("<span class='error'>"+j+"<a class='close'>Close</a></span>");l.find("a.close").click(function(){var m=c(this).parent();c(m).slideUp(1000,function(){c(m).remove();if(c("#ajax-error").children(".error").length==0){c("#ajax-error").remove()}});return false});k.removeClass("waiting")};c("#page-favourite").click(function(l){var k=c(this);if(k.hasClass("waiting")){return AJS.stopEvent(l)}k.addClass("waiting");var j=Confluence.getContextPath()+"/json/addfavourite.action";if(k.hasClass("selected")){j=Confluence.getContextPath()+"/json/removefavourite.action"}AJS.safeAjax({url:j,type:"POST",dataType:"json",data:{entityId:AJS.params.pageId},success:function(n){if(n.actionErrors){for(var m=0;m<n.actionErrors.length;m++){d(n.actionErrors,k)}return}if(n.errorMessage){d(n.errorMessage,k);return}k.removeClass("waiting");k.toggleClass("selected");k.toggleClass("ie-page-favourite-selected")},error:function(m){d("Server error while updating favourite",k)}});return AJS.stopEvent(l)});var h=c("#page-watch"),i=c("#page-unwatch"),e=c(h.parent("li")),g=c(i.parent("li"));if(h.hasClass("inactive")){e.addClass("assistive")}if(i.hasClass("inactive")){g.addClass("assistive")}var f=function(j,k,l){k.addClass("waiting");AJS.safe.ajax({url:j,type:"POST",dataType:"json",data:{entityId:AJS.params.pageId},success:function(n){if(n.actionErrors){for(var m=0;m<n.actionErrors.length;m++){d(n.actionErrors,k)}return}if(n.errorMessage){d(n.errorMessage,k);return}k.removeClass("waiting");k.toggleClass("inactive");l.toggleClass("inactive");k.parent("li").toggleClass("assistive");l.parent("li").toggleClass("assistive")},error:function(m){k.removeClass("waiting");d("Server error while updating favourite",menuItem)}})};h.click(function(j){f(Confluence.getContextPath()+"/pages/startwatching.action",h,i);h.addClass("waiting");return AJS.stopEvent(j)});i.click(function(j){f(Confluence.getContextPath()+"/pages/stopwatching.action",i,h);i.addClass("waiting");return AJS.stopEvent(j)});var a=c("#action-menu-link"),b=c("#add-menu-link");if(a.length){a.next().addClass("most-right-menu-item")}else{if(b.length){b.next().addClass("most-right-menu-item")}}c(".ajs-menu-bar").ajsMenu({isFixedPosition:true})});AJS.$(function(a){a("#header-menu-bar .ajs-menu-item").each(function(){var c=a(this),d=a(".ajs-drop-down",this),b=c.width();if(b>d.width()){d.width(b.valueOf()+50);AJS.log("Dropdown width override occurred")}})});
