function water_delivery_services_openNav() {
  jQuery(".sidenav").addClass('show');
}
function water_delivery_services_closeNav() {
  jQuery(".sidenav").removeClass('show');
}

( function( window, document ) {
  function water_delivery_services_keepFocusInMenu() {
    document.addEventListener( 'keydown', function( e ) {
      const water_delivery_services_nav = document.querySelector( '.sidenav' );

      if ( ! water_delivery_services_nav || ! water_delivery_services_nav.classList.contains( 'show' ) ) {
        return;
      }
      const elements = [...water_delivery_services_nav.querySelectorAll( 'input, a, button' )],
        water_delivery_services_lastEl = elements[ elements.length - 1 ],
        water_delivery_services_firstEl = elements[0],
        water_delivery_services_activeEl = document.activeElement,
        tabKey = e.keyCode === 9,
        shiftKey = e.shiftKey;

      if ( ! shiftKey && tabKey && water_delivery_services_lastEl === water_delivery_services_activeEl ) {
        e.preventDefault();
        water_delivery_services_firstEl.focus();
      }

      if ( shiftKey && tabKey && water_delivery_services_firstEl === water_delivery_services_activeEl ) {
        e.preventDefault();
        water_delivery_services_lastEl.focus();
      }
    } );
  }
  water_delivery_services_keepFocusInMenu();
} )( window, document );

var water_delivery_services_btn = jQuery('#button');

jQuery(window).scroll(function() {
  if (jQuery(window).scrollTop() > 300) {
    water_delivery_services_btn.addClass('show');
  } else {
    water_delivery_services_btn.removeClass('show');
  }
});

water_delivery_services_btn.on('click', function(e) {
  e.preventDefault();
  jQuery('html, body').animate({scrollTop:0}, '300');
});

jQuery(document).ready(function() {
    
  var owl = jQuery('.featured .owl-carousel');
    owl.owlCarousel({
    margin: 30,
    nav:true,
    autoplay : true,
    lazyLoad: true,
    autoplayTimeout: 5000,
    loop: true,
    dots: false,
    navText : ['<i class="fas fa-caret-left aria-hidden="true""></i>','<i class="fas fa-caret-right "aria-hidden="true"></i>'],
    responsive: {
      0: {
        items: 1
      },
      576: {
        items: 1
      },
      768: {
        items: 1
      },
      1000: {
        items: 2
      },
      1200: {
        items: 2
      }
    },
    autoplayHoverPause : false,
    mouseDrag: true,
  });
})

window.addEventListener('load', (event) => {
  jQuery(".loading").delay(2000).fadeOut("slow");
  jQuery(".loading2").delay(2000).fadeOut("slow");
});

jQuery('.header-search-wrapper .search-main').click(function(){
  jQuery('.search-form-main').toggleClass('active-search');
  jQuery('.search-form-main .search-field').focus();
});

jQuery("#top-slider h3.slider-heading").html(function() {
  var text2 = jQuery(this).text().trim().split(" ");
  var lastTwoWords = text2.splice(-2).join(" "); // Remove and store the last two words

  if (text2.length > 0) {
      var remainingText = text2.join(" ");
      return `${remainingText} <span class='last_slide_head'>${lastTwoWords}</span>`;
  } else {
      return `<span class='last_slide_head'>${lastTwoWords}</span>`;
  }
});

jQuery(window).scroll(function() {
  var data_sticky = jQuery('.main-header').attr('data-sticky');

  if (data_sticky == "true") {
    if (jQuery(this).scrollTop() > 1){
      jQuery('.main-header').addClass("stick_header");
    } else {
      jQuery('.main-header').removeClass("stick_header");
    }
  }
});