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

// sticky header
jQuery(window).scroll(function () {
  if (jQuery(window).scrollTop() >= 100) {
    jQuery('.is-sticky-on').addClass('sticky-head');
  }
  else {
    jQuery('.is-sticky-on').removeClass('sticky-head');
  }
});

jQuery(function ($) {
  $('.toggle-nav button').click(function (e) {
    $('body').toggleClass('show-main-menu');
    var element = $('.sidenav');
    luxury_interior_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 luxury_interior_trapFocus(element, namespace) {
  var luxury_interior_focusableEls = element.find('a, button');
  var luxury_interior_firstFocusableEl = luxury_interior_focusableEls[0];
  var luxury_interior_lastFocusableEl = luxury_interior_focusableEls[luxury_interior_focusableEls.length - 1];
  var KEYCODE_TAB = 9;

  luxury_interior_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 === luxury_interior_firstFocusableEl) {
        luxury_interior_lastFocusableEl.focus();
        e.preventDefault();
      }
    } else /* tab */ {
      if (document.activeElement === luxury_interior_lastFocusableEl) {
        luxury_interior_firstFocusableEl.focus();
        e.preventDefault();
      }
    }
  });
}

jQuery(document).ready(function () {
  jQuery('.owl-carousel').owlCarousel({
    loop: true,
    margin: 10,
    autoplay: true,
    nav: true,
    dots: false,
    smartSpeed: 250,
    rtl: true,
    navText: ['<i class="fas fa-long-arrow-alt-left"></i>', '<i class="fas fa-long-arrow-alt-right"></i>'],
    responsive: {
      0: {
        items: 1
      },
      600: {
        items: 1
      },
      1000: {
        items: 1
      }
    }
  })
});


/* ===============================================
  SCROLL TOP
============================================= */

jQuery(document).ready(function () {
  jQuery(window).scroll(function () {
    if (jQuery(this).scrollTop() > 0) {
      jQuery('#button').fadeIn();
    } else {
      jQuery('#button').fadeOut();
    }
  });
  jQuery('#button').click(function () {
    jQuery("html, body").animate({
      scrollTop: 0
    }, 600);
    return false;
  });
});

// Progress Bar
jQuery(document).ready(function ($) {

  $(window).on("scroll", function () {

    var scrollTop = $(window).scrollTop();
    var docHeight = $(document).height();
    var winHeight = $(window).height();
    var scrollPercent = (scrollTop / (docHeight - winHeight)) * 100;

    $("#progress-bar").css("width", scrollPercent + "%");
  });
});

//sticky copyright
window.addEventListener('scroll', function () {
  var luxury_interior_footer = document.querySelector('.sticky-copyright');
  if (!luxury_interior_footer) return;

  var luxury_interior_scrollTop = window.scrollY || document.documentElement.luxury_interior_scrollTop;

  if (luxury_interior_scrollTop >= 100) {
    luxury_interior_footer.classList.add('active-sticky');
  }
});

