(function( $ ) {
    'use strict';

// Mobile navigation toggle

    let toggleMobileNav = function() {
        let menu = $('.menu'),
            mobileNav = $('.mobile-nav'),
            menuOpen = false;

        // Check if .mobile-nav is visible
        if (mobileNav.is(':visible')) {
            mobileNav.click(function() {
                if (!menuOpen) {
                    menu.slideDown();
                    menuOpen = true;
                    mobileNav.addClass('active');
                } else {
                    menu.slideUp();
                    menuOpen = false;
                    mobileNav.removeClass('active');
                }
            });

            $(document).click(function(event) {
                if (!$(event.target).closest(menu).length && !$(event.target).closest(mobileNav).length && mobileNav.is(':visible')) {
                    if (menuOpen) {
                        menu.slideUp();
                        menuOpen = false;
                        mobileNav.removeClass('active');
                    }
                }
            });
        } else {
            menu.show();
            mobileNav.off("click");
            $(document).off("click", "**");
        }
    };

    toggleMobileNav();
    $(window).resize(toggleMobileNav);


})( jQuery );