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

	$('.mobile-nav .toggle-button').on( 'click', function() {
		$('.mobile-nav .main-navigation').slideToggle();
	});

	$('.mobile-nav-wrap .close ').on( 'click', function() {
		$('.mobile-nav .main-navigation').slideToggle();

	});

	$('<button class="submenu-toggle"></button>').insertAfter($('.mobile-nav ul .menu-item-has-children > a'));
	$('.mobile-nav ul li .submenu-toggle').on( 'click', function() {
		$(this).next().slideToggle();
		$(this).toggleClass('open');
	});

	//accessible menu for edge
	 $("#site-navigation ul li a").on( 'focus', function() {
	   $(this).parents("li").addClass("focus");
	}).on( 'blur', function() {
	    $(this).parents("li").removeClass("focus");
	 });

   	//Tabs
	jQuery('.tabs-stage .featured-mission-box').hide();
    jQuery('.tabs-stage div:first').show();
    jQuery('.tabs-nav li:first').addClass('tab-active');

    // Change tab class and display content
    jQuery('.tabs-nav a').on('click', function(event){
        event.preventDefault();
        jQuery('.tabs-nav li').removeClass('tab-active');
        jQuery(this).parent().addClass('tab-active');
        jQuery('.tabs-stage .featured-mission-box').hide();
        jQuery(jQuery(this).attr('href')).show();
    });

  //header-search
	jQuery('.search-show').click(function(){
		jQuery('.searchform-inner').css('visibility','visible');
	});

	jQuery('.close').click(function(){
		jQuery('.searchform-inner').css('visibility','hidden');
	});

});

var museum_exhibition_btn = jQuery('#button');

jQuery(window).scroll(function() {
  if (jQuery(window).scrollTop() > 300) {
    museum_exhibition_btn.addClass('show');
  } else {
    museum_exhibition_btn.removeClass('show');
  }
});
museum_exhibition_btn.on('click', function(e) {
  e.preventDefault();
  jQuery('html, body').animate({scrollTop:0}, '300');
});

window.addEventListener('load', (event) => {
    jQuery(".preloader").delay(1000).fadeOut("slow");
});

jQuery(window).scroll(function() {
    var museum_exhibition_data_sticky = jQuery(' .head_bg').attr('data-sticky');

    if (museum_exhibition_data_sticky == 1) {
      if (jQuery(this).scrollTop() > 1){  
        jQuery('.head_bg').addClass("sticky-head");
      } else {
        jQuery('.head_bg').removeClass("sticky-head");
      }
    }
});

function museum_exhibition_preloderFunction() {
    setTimeout(function() {           
        document.getElementById("page-top").scrollIntoView();
        
        $('#ctn-preloader').addClass('loaded');  
        // Once the preloader has finished, the scroll appears 
        $('body').removeClass('no-scroll-y');

        if ($('#ctn-preloader').hasClass('loaded')) {
            // It is so that once the preloader is gone, the entire preloader section will removed
            $('#preloader').delay(1000).queue(function() {
                $(this).remove();
                
                // If you want to do something after removing preloader:
                museum_exhibition_afterLoad();
                
            });
        }
    }, 3000);
}
function museum_exhibition_afterLoad() {
    // After Load function body!
}

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

    var museum_exhibition_owl = $('.test .owl-carousel');

    museum_exhibition_owl.owlCarousel({
        items: 1,
        margin: 20,
        nav: true,
        dots: false,
        loop: true,
        autoplay: true,
        autoplayTimeout: 3000,
        navText: [
            '<span class="owl-prev-text"><i class="fas fa-arrow-left"></i><br>Prev</span>',
            '<span class="owl-next-text"><i class="fas fa-arrow-right"></i><br>Next</span>'
        ]
    });

    // Total slides (real, not cloned)
    var museum_exhibition_totalItems = museum_exhibition_owl.find('.owl-item:not(.cloned)').length;

    // Add counter HTML
    museum_exhibition_owl.after(
        '<div class="owl-custom-nav">' +
            '<span class="owl-counter">' +
                '<span class="current">1</span>' +
                '<span class="divider"> / </span>' +
                '<span class="total">' + museum_exhibition_totalItems + '</span>' +
            '</span>' +
        '</div>'
    );

    // Counter update on slide change
    museum_exhibition_owl.on('changed.owl.carousel', function (event) {
        var museum_exhibition_currentItem = event.item.index - event.relatedTarget._clones.length / 2;
        var museum_exhibition_current = ((museum_exhibition_currentItem % museum_exhibition_totalItems) + museum_exhibition_totalItems) % museum_exhibition_totalItems + 1;

        $('.owl-counter .current').text(museum_exhibition_current);
    });

});