var DJMegaMenu;(function(e){DJMegaMenu=function(e,t){this.options={openDelay:250,closeDelay:500,animIn:"fadeIn",animOut:"fadeOut",animSpeed:"normal",duration:450,wrap:null,direction:"ltr",event:"mouseenter",eventClose:"mouseleave",parentOpen:0,touch:"ontouchstart"in window||navigator.MaxTouchPoints>0||navigator.msMaxTouchPoints>0,offset:0,wcag:1,overlay:0},this.init(e,t)},DJMegaMenu.prototype.init=function(n,s){var i=this;if(jQuery.extend(i.options,s),console.log(i.options),n.length){switch(n.find(".dj-hideitem").remove(),n.find(".modules-wrap ul.nav li.current").each(function(){var t=e(this);t.parents("ul.dj-submenu > li, li.dj-up").each(function(){t.addClass("active").find("> a").addClass("active")})}),n.find(".dj-up.active").length||n.find("li.active").first().parents("li").each(function(){e(this).addClass("active").find("> a").addClass("active")}),i.options.activeParent=n.find(".dj-up.active.parent").first(),i.options.menu=n,i.options.blurTimer=null,i.options.animSpeed){case"fast":i.options.duration=250;break;case"slow":i.options.duration=650}"0"==i.options.animIn&&"0"==i.options.animOut&&(i.options.duration=0),n.addClass("dj-megamenu-js "+i.options.animSpeed);var o=n.find("li.dj-up");if(i.kids=[],i.options.wrap=e("#"+i.options.wrap),i.options.wrap.length||(i.options.wrap=n.parents("div").last()),i.options.touch&&n.on("touchstart",function(e){e.stopPropagation()}),o.each(function(n){var s=e(this);i.kids[n]=new t(s,0,i,i.options)}),1==i.options.fixed&&e(document).on("djmegamenu:pageload",function(){i.makeSticky(n)}),(i.options.touch||"click"==i.options.eventClose)&&e(document).on("mouseup",function(t){e(t.target).closest(".dj-megamenu").length||i.hideAllSubs()}),1==i.options.wcag){var a=n.find("a");a.attr("tabindex",-1),a.first().attr("tabindex",0),e(document.body).on("keydown",function(e){"Escape"==e.key&&i.hideAllSubs()})}if(i.options.parentOpen>0&&i.options.activeParent.length&&i.options.activeParent.find("> a").trigger("click"),1==i.options.overlay){var u=e(document.body),r=i.options.menu.parent();e(document).on("djmegamenu:showsubmenu",function(){if(!u.hasClass("dj-megamenu-overlay")){u.addClass("dj-megamenu-overlay");var t=e('<div class="dj-megamenu-overlay-box" />');t.appendTo(r).fadeIn(300)}}),e(document).on("djmegamenu:hidesubmenu djmegamenu:leaveitem",function(){"mouseleave"==i.options.eventClose&&i.options.menu.find(".parent.hover").length||(u.removeClass("dj-megamenu-overlay"),r.find(".dj-megamenu-overlay-box").fadeOut(300,function(){e(this).remove()}))})}}},DJMegaMenu.prototype.hideAllSubs=function(){var t=this,n=t.options.menu.find(".hover");n.length&&(n.get().reverse(),e.each(n,function(t,n){e(n).trigger("djmegamenu:hideSub")}))},DJMegaMenu.prototype.makeSticky=function(t){var n=this;n.sticky=!1;var s=e("#"+t.attr("id")+"sticky"),i=e("<div />");i.css({display:"none",opacity:0,height:t.height()}),i.attr("id",t.attr("id")+"placeholder"),i.insertBefore(s),e(window).scroll(n.scroll.bind(n,s,t,i,!1)),e(window).resize(n.scroll.bind(n,s,t,i,!0)),n.scroll(s,t,i,!1),e(window).on("orientationchange",function(){setTimeout(function(){e(window).trigger("resize")},500)})},DJMegaMenu.prototype.scroll=function(t,n,s,i){var o=this;if(!n.is(":hidden")){var a=e(window).scrollTop(),u=(o.sticky?s.offset().top:n.offset().top)-parseInt(o.options.offset);if(o.sticky&&(a<u||i)&&(n.css({position:"",top:"",background:"",width:"",height:""}),n.removeClass("dj-megamenu-fixed"),t.find(".dj-stickylogo").css("display","none"),t.css({position:"",top:"",height:"",left:"",width:"",display:"none"}),s.css({display:"none","min-width":""}),n.find(".dj-up > .dj-subwrap").css({"max-height":"","overflow-y":""}),o.sticky=!1),!o.sticky&&a>=u){t.css({position:"fixed",top:parseInt(o.options.offset),left:0,width:"100%",display:"block"}),s.css({"min-width":n.outerWidth(!0),display:""});var r=0,l=t.find(".dj-stickylogo");l.length&&(l.css("display",""),l.hasClass("dj-align-center")&&(r=l.outerHeight(!0))),n.css({position:"fixed",top:parseInt(o.options.offset)+r,background:"transparent",height:"auto"}),n.addClass("dj-megamenu-fixed"),n.css("width",s.width()?s.width()+1:"auto"),s.css("height",n.outerHeight()),t.css("height",r+n.outerHeight());var d=e(window).height()-parseInt(o.options.offset)-t.height();n.find(".dj-up > .dj-subwrap").each(function(){e(this).find(".dj-subwrap").length||e(this).css({"max-height":d,"overflow-y":"auto"})}),o.sticky=!0}}};var t=function(e,t,n,s){this.options={},this.init(e,t,n,s)};t.prototype.init=function(t,n,s,i){var o=this;jQuery.extend(o.options,i),o.menu=t,o.level=n,o.parent=s,o.timer=null,o.blurTimer=null,o.sub=o.menu.find("> .dj-subwrap").first();var a=o.menu.find(".dj-submenu > li, .dj-subtree > li");a.length||(o.sub.remove(),o.menu.removeClass("parent"),o.menu.find("span.dj-drop").removeClass("dj-drop"),o.menu.find("i.arrow").remove());var u=o.menu.find("> a").first();u.attr("href")||o.menu.hasClass("separator")||o.menu.addClass("separator");var r=!!o.menu.hasClass("separator")&&o.menu;r&&u.css("cursor","pointer"),(o.options.touch||"click_all"==o.options.event||"click"==o.options.event&&r)&&u.on("touchend click",function(e){o.sub.length&&!o.menu.hasClass("hover")&&(e.preventDefault(),"touchend"==e.type&&o.menu.trigger("click"))}),o.menu.on("click",function(e){o.menu.hasClass("hover")?r&&"click"==o.options.event&&o.hideSub():o.showSub()}.bind(o)),("mouseenter"==o.options.event||"click"==o.options.event&&!r)&&o.menu.on("mouseenter",function(e){o.showSub()}.bind(o)),"mouseleave"==o.options.eventClose&&o.menu.on("mouseleave",function(t){e(t.target).is("input")||o.hideSub()}),o.menu.on("djmegamenu:showSub",function(e){e.stopPropagation(),o.showSub()}),o.menu.on("djmegamenu:hideSub",function(e){e.stopPropagation(),o.hideSub()}),o.sub.length&&o.initKids(),1==o.options.wcag&&o.keyboardNavigation()},t.prototype.keyboardNavigation=function(){var t=this,n=function(e){var t=e.next();if(e.is(":last-of-type")){var n=e.closest(".dj-subcol"),s=n.next(".dj-subcol"),i=n.prev(".dj-subcol"),o=n.parent().children().first(),a=e.closest(".nav.menu"),u=!!e.closest(".nav-child").length,r=a.length?"> .dj-submenu > li .menu > li":"> .dj-submenu > li";t=s.length&&!u?s.find(r).first():i.length&&!u?o.find(r).first():e.closest("ul").find("> li").first()}else t.length||(t=e);return t},s=function(e){var t=e.prev();if(e.is(":first-of-type")){var n=e.closest(".dj-subcol"),s=n.prev(".dj-subcol"),i=n.next(".dj-subcol"),o=n.parent().children().last(),a=e.closest(".nav.menu"),u=!!e.closest(".nav-child").length,r=a.length?"> .dj-submenu > li .menu > li":"> .dj-submenu > li";t=s.length&&!u?s.find(r).last():i.length&&!u?o.find(r).last():e.closest("ul").find("> li").last()}else t.length||(t=e);return t},i=function(e){var t=e.find(" > .dj-subwrap-in > .dj-subcol").last(),n=t.find(".nav.menu"),s=n.length?"> .dj-submenu > li .nav.menu > li":"> .dj-submenu > li",i=t.find(s).last();return i},o=function(e,t){var n,s=e.closest(".dj-subwrap-in");if(s.length){var i=e.closest(".nav.menu"),o=i.length?"> .dj-subcol > ul > li .nav.menu > li":"> .dj-subcol > ul > li";n=s.find(o)}else n=e.parent().find(" > li");var a=n.index(e),u=n.slice(a+1,n.length),r=n.slice(0,a),l=u.filter('[data-key="'+t+'"]'),d=r.filter('[data-key="'+t+'"]');return l.length?l.first():d.length?d.first():e},a=t.menu.find("a");a.each(function(){var t=e(this),n=t.text().charAt(0).toLowerCase();t.parent().attr("data-key",n)}),a.on("focus",function(){0===t.level&&(t.options.menu.find('[tabindex="0"]').attr("tabindex",-1),e(this).attr("tabindex",0))}),a.on("blur",function(){t.blurTimer=setTimeout(function(){if(!t.options.menu.find(":focus").length){for(var e=t;e.level>0;)e.hideSub(),e=e.parent;e.hideSub(),t.options.menu.find('[tabindex="0"]').attr("tabindex",-1),e.menu.find("> a").attr("tabindex",0)}},t.options.openDelay)}),t.options.menu.on("click",function(){clearTimeout(t.blurTimer)}),t.menu.on("keydown",function(a){switch(a.stopPropagation(),$this=e(this),a.key){case"ArrowRight":a.preventDefault(),t.hideSub(),0===t.level?n($this).find("> a").focus():t.sub.length?(t.showSub(),setTimeout(function(){t.sub.find("a").first().focus()},t.options.openDelay)):$this.hasClass("subtree")?$this.find(".dj-subtree > li > a").first().focus():n(t.menu.closest(".dj-up")).trigger("djmegamenu:showSub").find("> a").focus();break;case"ArrowLeft":if(a.preventDefault(),t.hideSub(),0===t.level)s($this).find("> a").focus();else if(1==t.level){var u=t.menu.closest(".dj-up");s(u).trigger("djmegamenu:showSub").find("> a").focus()}else t.parent.menu.trigger("djmegamenu:hideSub").find("> a").focus();return;case"ArrowUp":a.preventDefault(),0===t.level?t.sub.length&&(t.showSub(),setTimeout(function(){i(t.sub).find("> a").focus()},t.options.openDelay)):s($this).find("> a").focus();break;case"ArrowDown":a.preventDefault(),0===t.level?t.sub.length&&(t.showSub(),setTimeout(function(){t.sub.find("a").first().focus()},t.options.openDelay)):n($this).find("> a").focus();break;case" ":case"Spacebar":case"Enter":" "!=a.key&&"Spacebar"!=a.key||a.preventDefault(),t.sub.length&&(" "==a.key||"Spacebar"==a.key||t.menu.hasClass("separator"))?(t.showSub(),setTimeout(function(){t.sub.find("a").first().focus()},t.options.openDelay)):$this.find("> a")[0].click();break;case"Escape":t.level>0?(a.preventDefault(),t.parent.menu.trigger("djmegamenu:hideSub").find("> a").focus()):t.hideSub();break;case"Home":a.preventDefault(),$this.parent().children().first().find("> a").focus();break;case"End":a.preventDefault(),$this.parent().children().last().find("> a").focus();break;default:o($this,a.key).find("> a").focus()}}),t.menu.find(".nav.menu li, .dj-subtree li").on("keydown",function(t){switch($this=e(this),t.key){case"ArrowRight":t.preventDefault(),$this.hasClass("parent")?(t.stopPropagation(),$this.find("> ul > li > a").first().focus()):$this.parent().parent().hasClass("parent")&&(t.stopPropagation(),$this.parent().parent().next().find("> a").focus());break;case"ArrowLeft":t.preventDefault(),$this.parent().parent().hasClass("parent")&&(t.stopPropagation(),$this.parent().parent().find("> a").focus());break;case"ArrowUp":t.stopPropagation(),t.preventDefault(),s($this).find("> a").focus();break;case"ArrowDown":t.stopPropagation(),t.preventDefault(),n($this).find("> a").focus();break;case"Home":t.stopPropagation(),t.preventDefault(),$this.closest("ul").find("> li").first().find("> a").focus();break;case"End":t.stopPropagation(),t.preventDefault(),$this.closest("ul").find("> li").last().find("> a").focus();break;case"Escape":t.stopPropagation(),t.preventDefault(),$this.parents("li").find("> a").focus();break;case" ":case"Spacebar":t.stopPropagation()," "!=t.key&&"Spacebar"!=t.key||t.preventDefault(),$this.find("> a")[0].click();break;default:t.stopPropagation(),o($this,t.key).find("> a").focus()}})},t.prototype.showSub=function(){var t=this;clearTimeout(t.timer),t.menu.hasClass("hover")&&!t.sub.hasClass(t.options.animOut)||(t.sub.length&&t.sub.css("display","none"),t.timer=setTimeout(function(){clearTimeout(t.animTimer),t.menu.addClass("hover"),t.hideOther(),t.sub.length&&(t.sub.css("display",""),t.sub.removeClass(t.options.animOut),t.checkDir(),t.sub.addClass(t.options.animIn),t.menu.find("> a").attr("aria-expanded","true"),t.menu.trigger("djmegamenu:showsubmenu"),t.sub.find(".modules-wrap").length&&e(window).trigger("resize"))},t.options.openDelay))},t.prototype.hideSub=function(){var e=this;clearTimeout(e.timer),"2"===e.options.parentOpen&&e.options.activeParent.length&&e.options.activeParent.hasClass("hover")||(e.sub.length?e.timer=setTimeout(function(){e.sub.removeClass(e.options.animIn),e.sub.addClass(e.options.animOut),e.animTimer=setTimeout(function(){e.menu.removeClass("hover"),e.menu.find("> a").attr("aria-expanded","false"),e.menu.trigger("djmegamenu:hidesubmenu"),"2"===e.options.parentOpen&&e.options.activeParent.length&&e.options.activeParent.find("> a").trigger("click")},e.options.duration)},e.options.closeDelay):(e.menu.removeClass("hover"),e.menu.trigger("djmegamenu:leaveitem")))},t.prototype.checkDir=function(){var e=this;e.sub.css("left",""),e.sub.css("right",""),e.sub.css("margin-left",""),e.sub.css("margin-right","");var t=e.sub.offset(),n=e.options.wrap.offset();if(e.menu.hasClass("fullwidth"))return"ltr"==e.options.direction?e.sub.css("left",-t.left):e.sub.css("right",t.left),void e.sub.css("width",document.body.clientWidth);if(!e.menu.hasClass("fullsub"))if("ltr"==e.options.direction){var s=t.left+e.sub.outerWidth()-e.options.wrap.outerWidth()-n.left;(s>0||e.sub.hasClass("open-left"))&&(e.level?(e.sub.css("right",e.menu.outerWidth()),e.sub.css("left","auto")):e.sub.hasClass("open-left")?(e.sub.css("right",e.sub.css("left")),e.sub.css("left","auto")):e.sub.css("margin-left",-s))}else if("rtl"==e.options.direction){s=t.left-n.left;(s<0||e.sub.hasClass("open-right"))&&(e.level?(e.sub.css("left",e.menu.outerWidth()),e.sub.css("right","auto")):e.sub.hasClass("open-right")?(e.sub.css("left",e.sub.css("right")),e.sub.css("right","auto")):e.sub.css("margin-right",s))}},t.prototype.initKids=function(){var n=this;n.kids=[];var s=n.sub.find("> .dj-subwrap-in > .dj-subcol > ul.dj-submenu > li");s.each(function(s){var i=e(this);n.kids[s]=new t(i,n.level+1,n,n.options)})},t.prototype.hideOther=function(){var t=this;e.each(t.parent.kids,function(e,n){n.menu.hasClass("hover")&&n!=t&&(n.sub.length?(n.hideOtherSub(),n.sub.removeClass(n.options.animIn),n.sub.addClass(n.options.animOut),n.animTimer=setTimeout(function(){n.menu.removeClass("hover"),n.menu.find("> a").attr("aria-expanded","false")},t.options.duration)):n.menu.removeClass("hover"))})},t.prototype.hideOtherSub=function(){var t=this;e.each(t.kids,function(e,t){t.sub.length&&(t.hideOtherSub(),t.sub.removeClass(t.options.animIn),t.sub.removeClass(t.options.animOut)),t.menu.removeClass("hover")})}})(jQuery);var initMenu=function(){"undefined"==typeof jQuery?console.log("DJ-Megamenu: jQuery missing"):jQuery(".dj-megamenu[data-options]").each(function(){var e=jQuery(this);e.data();var t=e.data("options");e.removeAttr("data-options"),new DJMegaMenu(e,t)})};"loading"!==document.readyState?initMenu():document.addEventListener("DOMContentLoaded",function(){initMenu()}),window.addEventListener("load",function(){"undefined"==typeof jQuery?console.log("DJ-Megamenu: jQuery missing"):jQuery(document).trigger("djmegamenu:pageload")});