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

	var owl = jQuery('.banner .owl-carousel');
		owl.owlCarousel({
			margin:20,
			nav: true,
			autoplay : false,
			lazyLoad: true,
			autoplayTimeout: 3000,
			loop: false,
			dots:true,
			navText : ['<i class="fas fa-chevron-left"></i>','<i class="fas fa-chevron-right"></i> '],
			responsive: {
			0: {
				items: 1
			},
			600: {
				items: 1
			},
			1000: {
				items: 1
			}
		},
		autoplayHoverPause : true,
		mouseDrag: true
	});

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

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

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

var btn = jQuery('#button');

jQuery(window).scroll(function() {
  if (jQuery(window).scrollTop() > 300) {
    btn.addClass('show');
  } else {
    btn.removeClass('show');
  }
});
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 data_sticky = jQuery(' #masthead').attr('data-sticky');

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

jQuery(".banner_box h3").html(function() {
    var text = jQuery(this).text().trim().split(" ");
    var len = text.length;

    // Check if there are at least two words to wrap
    if (len >= 3) {
        var secondlast = text[len - 2];
        var thirdlast = text[len - 3];
        var lastWord = text[len - 1];
        var updatedLastTwoWord = `<span class='last_two_word_span'>${thirdlast +' '+secondlast}</span>`;
        var updatedLastWord = `<span class='last_word_span'>${lastWord}</span>`;
        
        text.splice(len - 3, 3, updatedLastTwoWord, updatedLastWord);
    }

    return text.join(" "); // Join the array of words back into a string and return as HTML content
});

jQuery("#about-section h3").html(function() {
    var text = jQuery(this).text().trim().split(" ");
    var len = text.length;

    // Check if there are at least two words to wrap
    if (len >= 1) {
        var lastWord = text[len - 1];
        var updatedLastWord = `<span class='about_last_word_span'>${lastWord}</span>`;
        text.splice(len - 1, 1, updatedLastWord); // Replace the last word
    }

    return text.join(" "); // Join the array of words back into a string and return as HTML content
});

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