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

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

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

      if ( ! shiftKey && tabKey && vw_modern_kitchen_lastEl === vw_modern_kitchen_activeEl ) {
        e.preventDefault();
        vw_modern_kitchen_firstEl.focus();
      }

      if ( shiftKey && tabKey && vw_modern_kitchen_firstEl === vw_modern_kitchen_activeEl ) {
        e.preventDefault();
        vw_modern_kitchen_lastEl.focus();
      }
    } );
  }
  vw_modern_kitchen_keepFocusInMenu();
  } )( window, document );

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

  /*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');
    }
  });

  // 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 Copyright
  $(window).scroll(function(){
    var sticky = $('.copyright-sticky'),
      scroll = $(window).scrollTop();

    if (scroll >= 100) sticky.addClass('copyright-fixed');
    else sticky.removeClass('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;
	});
});

// Title Color
jQuery(document).ready(function() {
  jQuery("#banner .banner-content .banner-title").each(function() {
    var vw_modern_kitchen_t = jQuery(this).text().trim();
    var vw_modern_kitchen_splitT = vw_modern_kitchen_t.split(" ");

    if (vw_modern_kitchen_splitT.length >= 2) {
      var vw_modern_kitchen_beforeLastTwo = vw_modern_kitchen_splitT.slice(0, -2).join(" ");
      var vw_modern_kitchen_lastTwo = vw_modern_kitchen_splitT.slice(-2).join(" ");

      var vw_modern_kitchen_newText = vw_modern_kitchen_beforeLastTwo + 
        ' <span class="title-text">' + vw_modern_kitchen_lastTwo + '</span>';

      jQuery(this).html(vw_modern_kitchen_newText);
    } else {
      jQuery(this).html(vw_modern_kitchen_t);
    }
  });
});

jQuery(document).ready(function () {
  var owl = jQuery('#blog-section .owl-carousel');
  owl.owlCarousel({
    margin: 30,
    loop: true,
    dots: false,
    autoplay: true,
    nav: true,
    navText: ['<i class="fa-solid fa-arrow-left"></i>', '<i class="fa-solid fa-arrow-right"></i>'],
    responsive: {
      0: { 
        items: 1 
      },
      768: { 
        items: 2 
      },
      992: { 
        items: 3 
      },
      1200: { 
        items: 4 
      }
    },
    autoplayHoverPause: true,
    mouseDrag: true
  });
});