// preloader
jQuery(window).on('load', function() {
  jQuery('#status').fadeOut();
  jQuery('#preloader').delay(350).fadeOut('slow');
  jQuery('body').delay(350).css({'overflow':'visible'});
})

// toggle button
jQuery(function($){
  $( '.toggle-nav button' ).click( function(e){
    $( 'body' ).toggleClass( 'show-main-menu' );
    var element = $( '.sidenav' );
    classic_marketing_agency_trapFocus( element );
  });

  $( '.close-button' ).click( function(e){
    $( '.toggle-nav button' ).click();
    $( '.toggle-nav button' ).focus();
  });
  $( document ).on( 'keyup',function(evt) {
    if ( $( 'body' ).hasClass( 'show-main-menu' ) && evt.keyCode == 27 ) {
      $( '.toggle-nav button' ).click();
      $( '.toggle-nav button' ).focus();
    }
  });
});

function classic_marketing_agency_trapFocus( element, namespace ) {
  var classic_marketing_agency_focusableEls = element.find( 'a, button' );
  var classic_marketing_agency_firstFocusableEl = classic_marketing_agency_focusableEls[0];
  var classic_marketing_agency_lastFocusableEl = classic_marketing_agency_focusableEls[classic_marketing_agency_focusableEls.length - 1];
  var KEYCODE_TAB = 9;

  classic_marketing_agency_firstFocusableEl.focus();

  element.keydown( function(e) {
    var isTabPressed = ( e.key === 'Tab' || e.keyCode === KEYCODE_TAB );

    if ( !isTabPressed ) {
      return;
    }

    if ( e.shiftKey ) /* shift + tab */ {
      if ( document.activeElement === classic_marketing_agency_firstFocusableEl ) {
        classic_marketing_agency_lastFocusableEl.focus();
        e.preventDefault();
      }
    } else /* tab */ {
      if ( document.activeElement === classic_marketing_agency_lastFocusableEl ) {
        classic_marketing_agency_firstFocusableEl.focus();
        e.preventDefault();
      }
    }
  });
}

jQuery(document).ready(function () {
  // Sticky Header
  jQuery(window).scroll(function () {
    var sticky = jQuery('.header-sticky'),
        scroll = jQuery(this).scrollTop();

    if (scroll >= 100) {
      sticky.addClass('header-fixed');
    } else {
      sticky.removeClass('header-fixed');
    }

    // Scroll to Top Button
    if (scroll > 0) {
      jQuery('#button').fadeIn();
    } else {
      jQuery('#button').fadeOut();
    }
  });

  jQuery('#button').click(function () {
    jQuery("html, body").animate({
      scrollTop: 0
    }, 600);
    return false;
  });

});

// slider JS
jQuery(document).ready(function($) {
    // Initialize the .slide-cat slider
    $('.slide-cat .owl-carousel').owlCarousel({
        loop: false,
        margin: 20, 
        nav: false,
        dots: false,
        autoplay: false,
        autoplayTimeout: 3000,
        autoplayHoverPause: true,
        items: 5,
        responsive: {
            0: { items: 3 }, // Responsive settings if needed
            768: { items: 3 },
        }
    });

    // Initialize the .slider-slide-content slider
    $('.slider-slide-content .owl-carousel').owlCarousel({
        loop: true,
        margin: 20, // Adjust margin as needed
        nav: false,
        dots: false,
        items: 1, // Display 1 item in slider-slide-content
        autoplay: true,
        autoplayTimeout: 3000,
        autoplayHoverPause: true,
    });

    // Click event handler for .slide-cat slider items
    $('.slide-cat .owl-carousel').on('click', '.owl-item', function(e) {
        e.preventDefault();
        var index = $(this).index();
        // Move slider-slide-content to corresponding item index
        $('.slider-slide-content .owl-carousel').trigger('to.owl.carousel', [index, 300, true]);
    });
});