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

    //Preloader
    jQuery('#preloader').delay(1500).fadeOut();
    jQuery('#loader').delay(1500).fadeOut("slow");

    if ($('.go-to-top').length) {
        var scrollTrigger = $('body').position(); // px
        goToTop = function () {

            var scrollTop = $(window).scrollTop();
            if (scrollTop > 150) {
                $('.footer-go-to-top').addClass('show');
            } else {
                $('.footer-go-to-top').removeClass('show');
            }
        };
        goToTop();
        $(window).on('scroll', function () {
            goToTop();
        });
        $('.go-to-top').on('click', function (e) {
            e.preventDefault();
            $('html,body').animate({
                scrollTop: scrollTrigger.top
            }, 700);
        });
    }

    // Mobile Menu Focus
    $(window).resize(fashion_outfit_navTrapp)

    function fashion_outfit_navTrapp() {
        var width = $(window).width();
        if (width < 992) {
            $('.main-navigation').on('keydown', function (e) {
                if ($('.main-navigation').hasClass('toggled')) {
                    var focusableEls = $('.main-navigation a[href]:not([disabled]), .main-navigation button');
                    var firstFocusableEl = focusableEls[0];
                    var lastFocusableEl = focusableEls[focusableEls.length - 1];
                    var KEYCODE_TAB = 9;
                    var KEYCODE_ESC = 27;
                    if (e.key === 'Tab' || e.keyCode === KEYCODE_TAB) {
                        if (e.shiftKey) /* shift + tab */ {
                            if (document.activeElement === firstFocusableEl) {
                                lastFocusableEl.focus();
                                e.preventDefault();
                            }
                        }
                        else /* tab */ {
                            if (document.activeElement === lastFocusableEl) {
                                firstFocusableEl.focus();
                                e.preventDefault();
                            }
                        }
                    }
    
                    if (e.keyCode === KEYCODE_ESC) {
                        console.log(e.keyCode);
                        $('.main-navigation').removeClass('toggled');
                        return;
                    }
                }
                
            });
        }
    }

    fashion_outfit_navTrapp()
  jQuery(document).ready(function() {
    var mainSlider = jQuery('#main-slider-wrap .main-slider .owl-carousel');
    var thumbnailSlider = jQuery('#main-slider-wrap .thumbnail-slider .owl-carousel');

    mainSlider.owlCarousel({
        items: 1,
        margin: 20,
        nav: false,
        autoplay: true,
        lazyLoad: false,
        loop: true,
        rtl: $('html').attr('dir') === 'rtl',  // Set RTL based on HTML direction
        dots: false,
        autoplayHoverPause: true,
        mouseDrag: true
    });

    thumbnailSlider.owlCarousel({
        items: 3,
        margin: 10,
        nav: false,
        navText: ['<i class="fas fa-arrow-left"></i>','<i class="fas fa-arrow-right"></i>'],
        autoplay: true,
        lazyLoad: false,
        rtl: $('html').attr('dir') === 'rtl',  // Set RTL based on HTML direction
        loop: true,
        dots: false,
        center: true,
        onInitialized: addFirstThumbnailClass,
        onTranslated: addFirstThumbnailClass
    });

    // Sync thumbnail with main slider
    mainSlider.on('changed.owl.carousel', function(event) {
        thumbnailSlider.trigger('to.owl.carousel', [event.item.index, 300, true]);
    });

    thumbnailSlider.on('click', '.owl-item', function() {
        var index = jQuery(this).index();
        mainSlider.trigger('to.owl.carousel', [index, 300, true]);
    });

    // Function to add class to the first thumbnail from the left
    function addFirstThumbnailClass() {
        jQuery('#main-slider-wrap .thumbnail-slider .owl-item').removeClass('first-thumbnail');
        jQuery('#main-slider-wrap .thumbnail-slider .owl-item.active').first().addClass('first-thumbnail');
    }
});

});

document.addEventListener('DOMContentLoaded', function() {
    const header = document.querySelector('.sticky-header');
    if (header) { // Check if header exists
        window.addEventListener('scroll', function() {
        if (window.scrollY > 0) {
            header.classList.add('stickyon');
        } else {
            header.classList.remove('stickyon');
        }
        });
    }
});