// Menus 
function honey_shop_menu_open_nav() {
  jQuery(".sidenav").addClass('show');
}
function honey_shop_menu_close_nav() {
  jQuery(".sidenav").removeClass('show');
}

( function( window, document ) {
  function honey_shop_keepFocusInMenu() {
    document.addEventListener( 'keydown', function( e ) {
      const honey_shop_nav = document.querySelector( '.sidenav' );

      if ( ! honey_shop_nav || ! honey_shop_nav.classList.contains( 'show' ) ) {
        return;
      }
      const elements = [...honey_shop_nav.querySelectorAll( 'input, a, button' )],
        honey_shop_lastEl = elements[ elements.length - 1 ],
        honey_shop_firstEl = elements[0],
        honey_shop_activeEl = document.activeElement,
        tabKey = e.keyCode === 9,
        shiftKey = e.shiftKey;

      if ( ! shiftKey && tabKey && honey_shop_lastEl === honey_shop_activeEl ) {
        e.preventDefault();
        honey_shop_firstEl.focus();
      }

      if ( shiftKey && tabKey && honey_shop_firstEl === honey_shop_activeEl ) {
        e.preventDefault();
        honey_shop_lastEl.focus();
      }
    } );
  }
  honey_shop_keepFocusInMenu();
} )( window, document );

jQuery('document').ready(function($){
	// preloader
  setTimeout(function () {
		jQuery("#preloader").fadeOut("slow");
  },1000);

  // Sticky Header
  $(window).scroll(function(){
		var sticky = $('.header-sticky'),
			scroll = $(window).scrollTop();

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

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

  var scrollTop = window.scrollY || document.documentElement.scrollTop;
  var windowHeight = window.innerHeight;
  var documentHeight = document.documentElement.scrollHeight;

  var isBottom = scrollTop + windowHeight >= documentHeight-100;

  if (scrollTop >= 100 && !isBottom) {
    sticky.classList.add('sidebar-fixed');
  } else {
    sticky.classList.remove('sidebar-fixed');
  }
});

/* Custom Cursor
 **-----------------------------------------------------*/
// Add this in custom-cursor.js
jQuery(document).ready(function($) {
  var cursor = $(".custom-cursor");
  var follower = $(".custom-cursor-follower");
  var offsetX = 15; // Set your desired horizontal offset
  var offsetY = 15; // Set your desired vertical offset

  $(document).mousemove(function(e) {
    cursor.css({
      top: e.clientY - offsetY + "px",
      left: e.clientX - offsetX + "px"
    });
    follower.css({
      top: e.clientY + "px",
      left: e.clientX + "px"
    });
  });

  $("a, button").hover(
    function() {
      cursor.addClass("active");
      follower.addClass("active");
    },
    function() {
      cursor.removeClass("active");
      follower.removeClass("active");
    }
  );
});

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

  var scrollTop = window.scrollY || document.documentElement.scrollTop;
  var windowHeight = window.innerHeight;
  var documentHeight = document.documentElement.scrollHeight;

  var isBottom = scrollTop + windowHeight >= documentHeight-100;

  if (scrollTop >= 100 && !isBottom) {
    sticky.classList.add('copyright-fixed');
  } else {
    sticky.classList.remove('copyright-fixed');
  }
});


// Scroller
jQuery(document).ready(function () {
	jQuery(window).scroll(function () {
    if (jQuery(this).scrollTop() > 100) {
      jQuery('.scrollup i').fadeIn();
    } else {
      jQuery('.scrollup i').fadeOut();
    }
	});
	jQuery('.scrollup i').click(function () {
    jQuery("html, body").animate({
      scrollTop: 0
    }, 600);
    return false;
	});
});
/* Progress Bar */
document.addEventListener("DOMContentLoaded", function () {
    const honey_shop_progressBar =
        document.getElementById("honey_shop_elemento_progress_bar");
    if (!honey_shop_progressBar) return;
    window.addEventListener("scroll", function () {
        const honey_shop_scrollTop =
            document.documentElement.scrollTop || document.body.scrollTop;
        const honey_shop_height =
            document.documentElement.scrollHeight -
            document.documentElement.clientHeight;
        const honey_shop_scrolled =
            (honey_shop_scrollTop / honey_shop_height) * 100;
        honey_shop_progressBar.style.width =
            honey_shop_scrolled + "%";
    });
});