var tdMenu={};
(function(){tdMenu={_itemsWithSubmenu:null,_mainMenu:null,_outsideClickArea:null,_outsideClickExcludedAreas:"#td-header-menu .sf-menu, #td-header-menu .sf-menu *, .menu-top-container, .menu-top-container *",_openMenuClass:"sfHover",_openMenuBodyClass:"td-open-menu",init:function(){var c=jQuery("#td-header-menu .sf-menu"),e=jQuery("#td-header-menu .sf-menu, .top-header-menu"),b=e.find(".menu-item-has-children > a, .td-mega-menu > a");b.append('<i class="td-icon-menu-down"></i>');c.supersubs({minWidth:10,maxWidth:20,
extraWidth:1});b.addClass("sf-with-ul");e.addClass("sf-js-enabled");b.parent().find("ul").first().css("display","none");tdMenu._mainMenu=c;tdMenu._itemsWithSubmenu=b;tdMenu._outsideClickArea=jQuery(window).not(tdMenu._outsideClickExcludedAreas);tdMenu._setHover(b,c)},_getSubmenuPosition:function(c){var e=jQuery(window).width();c=c.children("ul").first();if(0<c.length){var b=c.offset().left+c.width();b>e&&(c.parent().parent().hasClass("sf-menu")?c.css("left","-"+(b-e)+"px"):c.addClass("reversed").css("left",
"-"+(c.width()+0)+"px"))}},_getMouseAngleDirection:function(c,e,b,l){return Math.atan2(b-c,l-e)/Math.PI*180},_setHover:function(c,e){if(tdDetect.isTouchDevice)jQuery(document).on("touchstart","body",function(a){var d=c.parent(),b=jQuery("body");b.hasClass(tdMenu._openMenuBodyClass)&&!d.is(a.target)&&0===d.has(a.target).length&&(d.removeClass(tdMenu._openMenuClass),d.children("ul").hide(),b.removeClass(tdMenu._openMenuBodyClass))}),c.on("touchstart",function(a){a.preventDefault();a.stopPropagation();
var b=jQuery(this);a=b.parent();var f=jQuery("body");a.hasClass(tdMenu._openMenuClass)?null!==b.attr("href")&&"#"!==b.attr("href")?window.location.href=b.attr("href"):((a.parent().hasClass("sf-menu")||a.parent().hasClass("top-header-menu"))&&f.removeClass(tdMenu._openMenuBodyClass),a.removeClass(tdMenu._openMenuClass),a.find("ul").hide(),a.find("li").removeClass(tdMenu._openMenuClass)):(a.parent().hasClass("sf-menu")||a.parent().hasClass("top-header-menu")?(c.parent().removeClass(tdMenu._openMenuClass),
c.parent().children("ul").hide()):(b=a.siblings(),b.removeClass(tdMenu._openMenuClass),b.find("ul").hide(),b.find("li").removeClass(tdMenu._openMenuClass)),a.addClass(tdMenu._openMenuClass),a.children("ul").show(),tdMenu._getSubmenuPosition(a),f.addClass(tdMenu._openMenuBodyClass))});else{var b={},l,k=!0;e.on("mouseleave",function(){c.parent().removeClass(tdMenu._openMenuClass);c.parent().children("ul").hide();b={}});e.find(".menu-item").hover(function(){var a=jQuery(this),d="",f,e;if(a.hasClass("menu-item-has-children")||
a.hasClass("td-mega-menu"))if(a.parent().hasClass("sf-menu"))if(jQuery.isEmptyObject(b))a.addClass(tdMenu._openMenuClass),a.children("ul").show(),b=a;else{if(a[0]!==b[0]){var g=e=f=0;var h=null;!0===k&&(k=!1,l=setTimeout(function(){c.parent().removeClass(tdMenu._openMenuClass);c.parent().children("ul").hide();a.addClass(tdMenu._openMenuClass);a.children("ul").show();b=a},400));a.on("mousemove",function(d){5<=f?(f=0,h=tdMenu._getMouseAngleDirection(e,g,d.pageX,d.pageY),e=d.pageX,g=d.pageY):(f++,0===
e&&0===g&&(e=d.pageX,g=d.pageY));null!==h&&(85<h||-85>h)&&(c.parent().removeClass(tdMenu._openMenuClass),c.parent().children("ul").hide(),a.addClass(tdMenu._openMenuClass),a.children("ul").show(),a.off("mousemove"),clearTimeout(l),k=!0,b=a)})}}else d=a.siblings(),d.removeClass(tdMenu._openMenuClass),d.find("ul").hide(),d.find("li").removeClass(tdMenu._openMenuClass),a.addClass(tdMenu._openMenuClass),a.children("ul").show(),tdMenu._getSubmenuPosition(a);else a.parent().hasClass("sf-menu")||a.parent().hasClass("top-header-menu")?
jQuery.isEmptyObject(b)||(g=e=f=0,h=null,!0===k&&(k=!1,l=setTimeout(function(){c.parent().removeClass(tdMenu._openMenuClass);c.parent().children("ul").hide();b={}},400)),a.on("mousemove",function(d){5<=f?(f=0,h=tdMenu._getMouseAngleDirection(e,g,d.pageX,d.pageY),e=d.pageX,g=d.pageY):(f++,0===e&&0===g&&(e=d.pageX,g=d.pageY));null!==h&&(85<h||-85>h)&&(c.parent().removeClass(tdMenu._openMenuClass),c.parent().children("ul").hide(),a.off("mousemove"),clearTimeout(l),k=!0,b={})})):(b=a.parent(),d=a.siblings(),
d.removeClass(tdMenu._openMenuClass),d.find("ul").hide(),d.find("li").removeClass(tdMenu._openMenuClass))},function(){var a=jQuery(this);!1===k&&(clearTimeout(l),k=!0);a.off("mousemove")})}},unsetHover:function(){null!==tdMenu._itemsWithSubmenu&&tdMenu._itemsWithSubmenu.off();null!==tdMenu._outsideClickArea&&tdMenu._outsideClickArea.off()}}})();jQuery().ready(function(){tdMenu.init()});
