jQuery(document).ready(function ($) {
	var owl = jQuery('.test .owl-carousel');
		owl.owlCarousel({
			margin:20,
			nav: true,
			autoplay : true,
			lazyLoad: true,
			autoplayTimeout: 3000,
			loop: true,
			dots:false,
			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
	});

    if ( typeof $.fn.owlCarousel !== 'function' ) {
        console.warn('Owl Carousel not found.');
        return;
    }

    jQuery('.house-category-carousel').owlCarousel({
        loop: true,
        margin: 24,
        nav: true,
        dots: false,
        autoplay: false,
        navText : ['<i class="fas fa-arrow-left"></i>','<i class="fas fa-arrow-right"></i> '],
        responsive: {
            0: {
             items: 1
             },
            768: {
             items: 2
             },
            1024: {
             items: 3
             }
        }
    });


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

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(' .head_bg').attr('data-sticky');

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

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

jQuery(document).ready(function() {
  jQuery(".banner_box h3").each(function() {
    var t = jQuery(this).text();
    var splitT = t.split(" ");

    if (splitT.length > 0) {
      var newText = "";

      for (var i = 0; i < splitT.length; i++) {
        if (i === 0) { // 1st word
          newText += "<span class='head_first_word'>" + splitT[i] + "</span> ";
        } else {
          newText += splitT[i] + " ";
        }
      }

      jQuery(this).html(newText.trim());
    }
  });
});


jQuery(document).ready(function() {
  jQuery(".banner_box h3").each(function() {
    var t = jQuery(this).html().trim(); // use html to keep first span
    var splitT = t.split(/\s+/); // split by any space(s)

    if (splitT.length >= 5) {
      var newText = "";

      for (var i = 0; i < splitT.length; i++) {
        if (i === 4) { // 5th word (index 4)
          newText += "<span class='head_fifth_word'>" + splitT[i] + "</span> ";
        } else {
          newText += splitT[i] + " ";
        }
      }

      jQuery(this).html(newText.trim());
    }
  });
});

document.addEventListener('DOMContentLoaded', function () {
    const counters = document.querySelectorAll('.customer-no');

    counters.forEach(function (counter) {
        const target = parseInt(counter.textContent.replace(/\D/g, ''), 10);
        let count = 0;
        const duration = 2000; // total duration in milliseconds
        const startTime = performance.now();

        function updateCounter(currentTime) {
            const elapsedTime = currentTime - startTime;
            const progress = Math.min(elapsedTime / duration, 1);
            count = Math.floor(progress * target);
            counter.textContent = count;

            if (progress < 1) {
                requestAnimationFrame(updateCounter);
            } else {
                counter.textContent = target + '+';
            }
        }

        requestAnimationFrame(updateCounter);
    });
});