// Scroll to Top
window.onscroll = function() {
  const festival_events_button = document.querySelector('.scroll-top-btn');
  if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
    festival_events_button.style.display = "block";
  } else {
    festival_events_button.style.display = "none";
  }
};

document.querySelector('.scroll-top-btn a').onclick = function(event) {
  event.preventDefault();
  window.scrollTo({top: 0, behavior: 'smooth'});
};

// Main Slider
jQuery(document).ready(function($) {
  const section = $('.slider-section');
  const owl = section.find('.owl-carousel').owlCarousel({
    loop: true,
    nav: false,
    dots: false,
    rtl: false,
    items: 1,
    autoplay: true,
    animateOut: 'fadeOut',
    animateIn: 'fadeIn',
  });

  // Custom navigation buttons
  section.find('.custom-next').click(function() {
    owl.trigger('next.owl.carousel');
  });

  section.find('.custom-prev').click(function() {
    owl.trigger('prev.owl.carousel');
  });
});

// Remove Time
jQuery(document).ready(function($) {
  $('.event-section .event-content .tribe-block .tribe-event-date-start').each(function() {
    let text = $(this).text().trim();
    let dateOnly = text.replace(/\b\d{1,2}:\d{2}\s?(am|pm|AM|PM)\b/, '').replace('@', '').replace('–', '').trim();
    $(this).text(dateOnly);
  });
});

// Align Vertical
jQuery(document).ready(function($) {
  $('.event-section .event-content .tribe-block .tribe-event-date-start').each(function() {
    let text = $(this).text().trim();
    let parts = text.split(' ');
    if (parts.length === 2) {
      $(this)
        .attr('data-month', parts[0])
        .attr('data-day', parts[1])
        .text('');
    }
  });
});