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





 $(".menu-icon").sidr({
      name: 'sidr-existing-content',
      source: '.logo, #caeliora-mobile-header, #site-navigation',
      displace: false,
      renaming: false
  });

 $("<span class='open-sidr'></span>").insertAfter(".sidr .menu-item-has-children > a")
  $(".sidr")
    .find(".open-sidr")
    .click(function () {
      $(this).next().slideToggle("fast")
    })
  $(".open-sidr").click(function () {
    $(this).toggleClass("close")
  })

  $("a.close-mobile-menu").on("click", function (e) {
    e.preventDefault()
    $.sidr("close", "sidr-existing-content")
  })

  $('.menu-toggle').click(function(){
    $('.close-mobile-menu').focus();
  });

  $(window).on('load resize', function() {
        if ($(window).width() < 1024 && $(window).width() >= 768) {
            $('.main-navigation-links').find("a").unbind('keydown');
            $('.main-navigation-links').find("li").last().bind('keydown', function(e) {
                if (e.which === 9) {
                    e.preventDefault();
                    $('.sidr-inner').find('.close-mobile-menu').focus();
                }
            });
        } else if ($(window).width() < 768) {
            $('.main-navigation-links').find("li").unbind('keydown');
            $('.main-navigation-links').find("a").last().bind('keydown', function(e) {
                if (e.which === 9) {
                    e.preventDefault();
                    $('.sidr-inner').find('.close-mobile-menu').focus();
                }
            });
        } else {
            $('.sidr-inner').find("li").unbind('keydown');
            $('.sidr-inner').find("a").unbind('keydown');
        }
    });

    

  // Swiper Slider
  const progressCircle = document.querySelector(".autoplay-progress svg");
  const progressContent = document.querySelector(".autoplay-progress span");
  var swiper = new Swiper(".mySwiper", {
    spaceBetween: 0,
    centeredSlides: true,
    autoplay: {
      delay: 10000,
      disableOnInteraction: false
    },
    pagination: {
      el: ".swiper-pagination",
      clickable: true
    },
    effect: 'fade',
    on: {
      autoplayTimeLeft(s, time, progress) {
        progressCircle.style.setProperty("--progress", 1 - progress);
        progressContent.textContent = `${Math.ceil(time / 1000)}s`;
      }
    }
  });


  // ============= Begin of Second word colour change =============
  var toBold = document.getElementsByClassName('home-section-header');
  for (var i=0; i<toBold.length; ++i) {
    boldSecondWord(toBold[i]);
  }

  function boldSecondWord(elem) {
    elem.innerHTML = elem.textContent.replace(/\w+ (\w+)/, function(s, c) {
      return s.replace(c, '<span class="second-word-color">'+c+'</scan>');
    });
  }

// ============= End of Second word colour change =============
});