jQuery(document).ready(function ($) {
	var travel_planning_owl = $('#topdestination .owl-carousel');
	travel_planning_owl.owlCarousel({
	margin: 20,
	nav: false,
	dots: false,
	loop: false,
	autoplay: true,
	lazyLoad: true,
	responsive: {
		0: { items: 1},
		768: { items: 2 },
		1024: { items: 4 },
		1200: { items: 6 }
	},
	onInitialized: travel_planning_setExpand,
	onTranslated: travel_planning_setExpand
	});

	function travel_planning_setExpand() {
	$('#topdestination .owl-item').removeClass('expand');
	$('#topdestination .owl-item.active').eq(1).addClass('expand');
	}

	// Hover effect
	$('#topdestination').on('mouseenter', '.owl-item', function () {
	$('#topdestination .owl-item').removeClass('expand');
	$(this).addClass('expand');
	});

	$('#topdestination').on('mouseleave', function () {
	travel_planning_setExpand();
	});

	//Mobile Navigation
	$('.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 .page_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");
	 });
});

var travel_planning_btn = jQuery('#button');

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

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

//Sticky Header
jQuery(window).scroll(function() {
    var travel_planning_data_sticky = jQuery(' .head_bg').attr('data-sticky');

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

//Preloader
function travel_planning_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:
                travel_planning_afterLoad();
                
            });
        }
    }, 3000);
}
function travel_planning_afterLoad() {
    // After Load function body!
}