(function($) {
    "use strict";

    $(document).ready(function() {

		// 1. Menu Click JS (Click + Space/Enter Keyboard Support)
		$('.menu-click a, .close-menu a').on('click keydown', function(e){
            if (e.type === 'click' || e.key === 'Enter' || e.key === ' ' || e.keyCode === 32 || e.keyCode === 13) {
                e.preventDefault();
			    $('.menu-inner').toggleClass('active');
            }
		});

        // 2. Click outside to close menu
        $(document).on('click', function(event) {
            if ($('.menu-inner').hasClass('active')) {
                if (!$(event.target).closest('.menu-inner').length && !$(event.target).closest('.menu-click').length) {
                    $('.menu-inner').removeClass('active');
                }
            }
        });

		$(".close-menu a").focusout(function(){
			$("#side-menu > li:first-child > a").focus();
			$(".menu-click").addClass('active');
		});

		// 3. Search Form JS (Click + Space/Enter Keyboard Support)
		$('.one-elementor-search-icon, .one-elementor-search-close').on('click keydown', function(e){
            if (e.type === 'click' || e.key === 'Enter' || e.key === ' ' || e.keyCode === 32 || e.keyCode === 13) {
                e.preventDefault();
			    $('.search-form-main').toggleClass('active');
            }
		});

		$(".one-elementor-search-close").focusout(function(){
			$(".search-form label input").focus();
			$(".one-elementor-search-icon").addClass('active');
		});
	});

	jQuery(window).on('load', function() {
	    // init Masonry
		var $grid = $('.one-elementor-masonry').masonry({
			// options
			itemSelector: '.one-elementor-masonry-item',
		});
		// layout Masonry after each image loads
		$grid.imagesLoaded().progress( function() {
			$grid.masonry('layout');
		});
	});

})(jQuery);