jQuery(document).ready(function ($) {
    "use strict";
    var isMobile = false;
    if (/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
        $('html').addClass('touch');
        isMobile = true;
    } else {
        $('html').addClass('no-touch');
        isMobile = false;
    }
    
// Banner Slider
var swiper = new Swiper('.theme-main-carousel', {
    centeredSlides: true,
    slidesPerView: 1,
    loop: true,
    spaceBetween: 0,
    speed: 2000,
    roundLengths: true,
    keyboard: true,
    parallax: true,
    mousewheel: false,
    grabCursor: true,
    preloadImages: false,
    lazy: {
        loadPrevNext: true,
        loadOnTransitionStart: true,
    },
    watchSlidesProgress: true,
    autoplay: {
        delay: 2000, // time in milliseconds (5000 = 5 seconds)
        disableOnInteraction: false, // keep autoplay after user interaction
    },
    navigation: {
        nextEl: '.custom-next',
        prevEl: '.custom-prev',
    },
    breakpoints: {
        768: {
            slidesPerView: 1,
        },
        1200: {
            slidesPerView: 1,
        },
        1600: {
            slidesPerView: 1,
        }
    }
});

// Hide navigation if there is only one slide
var totalSlides = document.querySelectorAll('.theme-main-carousel .swiper-slide').length;

// Note: Swiper duplicates slides for looping, so we check original slides
var realSlides = swiper.slides.length / (swiper.params.loop ? 3 : 1);

if (realSlides <= 1 && document.querySelector('.custom-navigation') != null) {
    document.querySelector('.custom-navigation').style.display = 'none';
}

    // Scroll To
    $(".scroll-content").click(function () {
        $('html, body').animate({
            scrollTop: $("#site-content").offset().top
        }, 500);
    });
    // Aub Menu Toggle
    $('.submenu-toggle').click(function () {
        $(this).toggleClass('button-toggle-active');
        var currentClass = $(this).attr('data-toggle-target');
        $(currentClass).toggleClass('submenu-toggle-active');
    });
    $('.skip-link-menu-start').focus(function () {
        if (!$("#offcanvas-menu #primary-nav-offcanvas").length == 0) {
            $("#offcanvas-menu #primary-nav-offcanvas ul li:last-child a").focus();
        }
    });
    // Toggle Menu
    $('.navbar-control-offcanvas').click(function () {
        $(this).addClass('active');
        $('body').addClass('body-scroll-locked');
        $('#offcanvas-menu').toggleClass('offcanvas-menu-active');
        $('.button-offcanvas-close').focus();
    });
    $('.offcanvas-close .button-offcanvas-close').click(function () {
        $('#offcanvas-menu').removeClass('offcanvas-menu-active');
        $('.navbar-control-offcanvas').removeClass('active');
        $('body').removeClass('body-scroll-locked');
        setTimeout(function () {
            $('.navbar-control-offcanvas').focus();
        }, 300);
    });
    $('#offcanvas-menu').click(function () {
        $('#offcanvas-menu').removeClass('offcanvas-menu-active');
        $('.navbar-control-offcanvas').removeClass('active');
        $('body').removeClass('body-scroll-locked');
    });
    $(".offcanvas-wraper").click(function (e) {
        e.stopPropagation(); //stops click event from reaching document
    });
    $('.skip-link-menu-end').on('focus', function () {
        $('.button-offcanvas-close').focus();
    });
    // Data Background
    var pageSection = $(".data-bg");
    pageSection.each(function (indx) {
        if ($(this).attr("data-background")) {
            $(this).css("background-image", "url(" + $(this).data("background") + ")");
        }
    });
    // Scroll to Top on Click
    $('.to-the-top').click(function () {
        $("html, body").animate({
            scrollTop: 0
        }, 700);
        return false;
    });

});

//Loader
jQuery(window).on('load', function() {
  jQuery(".preloader").delay(2000).fadeOut("slow");
});

//Sticky
jQuery(window).scroll(function() {
    var data_sticky = jQuery('#center-header').attr('data-sticky');

    if (data_sticky == "true") {
      if (jQuery(this).scrollTop() > 1){
        jQuery('.Stickyy').addClass("stick_head");
      } else {
        jQuery('.Stickyy').removeClass("stick_head");
      }
    }
  });

// Second section owl js

jQuery(function(jQuery) {
   var owl = jQuery('.most-read-div .owl-carousel');
        owl.owlCarousel({
            margin: 20,
            nav: false,
            dots:false,
            autoplay:true,
            autoplayTimeout:2000,
            autoplayHoverPause:true,
            loop: true,
            navText : ['<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M34.5 239L228.9 44.7c9.4-9.4 24.6-9.4 33.9 0l22.7 22.7c9.4 9.4 9.4 24.5 0 33.9L131.5 256l154 154.8c9.3 9.4 9.3 24.5 0 33.9l-22.7 22.7c-9.4 9.4-24.6 9.4-33.9 0L34.5 273c-9.4-9.4-9.4-24.6 0-33.9z"/></svg>','<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M285.5 273L91.1 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.7-22.7c-9.4-9.4-9.4-24.5 0-33.9L188.5 256 34.5 101.3c-9.3-9.4-9.3-24.5 0-33.9l22.7-22.7c9.4-9.4 24.6-9.4 33.9 0L285.5 239c9.4 9.4 9.4 24.6 0 33.9z"/></svg>'],
            responsive: {
              0: {
                items: 1
              },
              600: {
                items: 2
              },
              1020: {
                items: 3
            }
        }
    })
});