jQuery(document).ready(function ($) {


    "use strict";


    function togglerAppend(el) {


        $(el).each(function () {


            $(this).before(
                '<button class="elementpress-menu-hamburger elementpress-menu-toggler">'


                + '<span class="elementpress-menu-hamburger-icon"></span>'


                + '<span class="elementpress-menu-hamburger-icon"></span>'


                + '<span class="elementpress-menu-hamburger-icon"></span>'


                + '</button>'
            );


        })


    }


    togglerAppend($('.elementpress-menu-container'));


    $('.elementpress-menu-container').each(function (__, e) {


        $(e).after('<div class="elementpress-menu-overlay elementpress-menu-offcanvas-elements elementpress-menu-toggler"></div>');


    });


    function elementpress_event_manager(_event, _selector, _fn) {


        $(document).on(_event, _selector, _fn);


    }


    elementpress_event_manager('click', '.elementpress-dropdown-has > a', function (e) {


        e.preventDefault();


        var menu = $(this).parents('.elementpress-navbar-nav');


        var li = $(this).parent();


        var dropdown = li.find('>.elementpress-dropdown, >.elementpress-megamenu-panel');


        dropdown.find('.elementpress-dropdown-open').removeClass('elementpress-dropdown-open');


        jQuery(window).on('resize', function () {


            if (jQuery(window).width() > 991) {


                jQuery(dropdown).removeClass('elementpress-dropdown-open');


            }


        })


        if (dropdown.hasClass('elementpress-dropdown-open')) {


            dropdown.removeClass('elementpress-dropdown-open');


        } else {


            dropdown.addClass('elementpress-dropdown-open');


        }


    });


    elementpress_event_manager('click', '.elementpress-menu-toggler', function (e) {


        e.preventDefault();


        var parent_conatiner = $(this).parents('.elementpress-menu-container').parent();


        if (parent_conatiner.length < 1) {


            parent_conatiner = $(this).parent();


        }


        var off_canvas_class = parent_conatiner.find('.elementpress-menu-offcanvas-elements');


        jQuery(window).on('resize', function () {


            if (jQuery(window).width() > 991) {


                off_canvas_class.removeClass('active');


            }


        })


        if (off_canvas_class.hasClass('active')) {


            off_canvas_class.removeClass('active');


        } else {


            off_canvas_class.addClass('active');


        }


    });


}); // end ready function