jQuery(document).ready(function($) {
  var scroll = $(window).scrollTop();
  var scrollup = $('.scroll-top');
  /*------------------------------------------------
            Scroll Top
  ------------------------------------------------*/
  scrollup.click(function () {
    $('html, body').animate({
      scrollTop: '0px'
    }, 800);
    return false;
  });
  $(window).scroll(function () {
    var scroll = $(window).scrollTop();
    if (scroll >= 200) {
      scrollup.fadeIn();
    } else {
      scrollup.fadeOut();
    }
  });
});

// Main Slider
jQuery(function ($) {
  const window_cleaning_section = $('.slider-section');
  const window_cleaning_owl = window_cleaning_section.find('.owl-carousel').owlCarousel({
    items: 1,
    loop: true,
    margin: 15,
    nav: false,
    dots: false,
    autoplay: true,
  });

  const window_cleaning_dots = window_cleaning_section.find('.custom-dots').empty();

  window_cleaning_section.find('.owl-item:not(.cloned)').each((i, el) => {
    const window_cleaning_img = $(el).find('img').attr('src');
    if (window_cleaning_img) window_cleaning_dots.append(`<button class="dot" data-i="${i}"><img src="${window_cleaning_img}"></button>`);
  });

  window_cleaning_dots.on('click', '.dot', function () {
    window_cleaning_owl.trigger('to.owl.carousel', [$(this).data('i'), 300]);
  });

  window_cleaning_owl.on('changed.owl.carousel', e => {
    const window_cleaning_i = (e.item.index - e.relatedTarget._clones.length / 2 + e.item.count) % e.item.count;
    window_cleaning_dots.find('.dot').removeClass('active').eq(window_cleaning_i).addClass('active');
  });

  window_cleaning_dots.find('.dot').first().addClass('active');
});

jQuery(document).ready(function() {
  jQuery('.testimonial-section .owl-carousel').owlCarousel({
    loop: true,
    margin: 20,
    nav: false,
    dots: true,
    rtl: false,
    responsive: {
      0: { 
        items: 1 
      },
      600: { 
        items: 2 
      },
      992: { 
        items: 3 
      },
      1200: { 
        items: 4 
      }
    },
    autoplay: true,
  });
});

jQuery(document).ready(function() {
  jQuery('.latest-news .owl-carousel').owlCarousel({
    loop: true,
    margin: 40,
    nav: true,
    navText: ["<i class='fa-solid fa-angles-left'></i>", "<i class='fa-solid fa-angles-right'></i>"], 
    dots: false,
    rtl: false,
    responsive: {
    0: { 
      items: 1 
    },
    600: { 
      items: 2 
    },
    992: { 
      items: 3 
    },
    1200: { 
      items: 4 
    }
  },
    autoplay: true,
  });
});