// dropdown category
jQuery(document).ready(function(){
  jQuery(".category-dropdown").hide();
  
  jQuery("button.category-btn").click(function(){
    jQuery(".category-dropdown").toggle();
  });

  // Handle focus using Tab and Shift+Tab
  jQuery(".category-btn, .category-dropdown").on("keydown", function(e) {
    var dropdownItems = jQuery(".category-dropdown").find("a"); // Assuming dropdown items are represented by <a> tags
    
    if (e.keyCode === 9) { // Tab key
      if (!e.shiftKey && document.activeElement === dropdownItems.last().get(0)) {
        e.preventDefault();
        jQuery(".category-btn").focus();
      } else if (e.shiftKey && document.activeElement === dropdownItems.first().get(0)) {
        e.preventDefault();
        jQuery(".category-btn").focus();
      }
    }
  });
});

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

  if ( typeof $.fn.owlCarousel !== 'function' ) {
		console.warn('Owl Carousel not found.');
		return;
	}

	var online_mobile_accessories_owl = jQuery('.slider .owl-carousel');
		online_mobile_accessories_owl.owlCarousel({
			margin:20,
			nav: true,
			autoplay : true,
			lazyLoad: true,
			autoplayTimeout: 3000,
			loop: true,
			dots:false,
			navText : ['<i class="fas fa-arrow-left"></i>','<i class="fas fa-arrow-right"></i> '],
			responsive: {
			0: {
				items: 1
			},
			600: {
				items: 1
			},
			1000: {
				items: 1
			}
		},
		autoplayHoverPause : true,
		mouseDrag: true
	});

	//Mobile Navigation
	$('.mobile-nav .toggle-button').on( 'click', function() {
		$('.mobile-nav .main-navigation').slideToggle();
	});

	$('.mobile-nav-wrap .close ').on( 'click', function() {
		$('.mobile-nav .main-navigation').slideToggle();

	});

	$('<button class="submenu-toggle"></button>').insertAfter($('.mobile-nav ul .menu-item-has-children > a, .mobile-nav ul .page_item_has_children > a'));
	$('.mobile-nav ul li .submenu-toggle').on( 'click', function() {
		$(this).next().slideToggle();
		$(this).toggleClass('open');
	});

	//accessible menu for edge
	 $("#site-navigation ul li a").on( 'focus', function() {
	   $(this).parents("li").addClass("focus");
	}).on( 'blur', function() {
	    $(this).parents("li").removeClass("focus");
	 });
});

var online_mobile_accessories_btn = jQuery('#button');

//Scroll To Top
jQuery(window).scroll(function() {
  if (jQuery(window).scrollTop() > 300) {
    online_mobile_accessories_btn.addClass('show');
  } else {
    online_mobile_accessories_btn.removeClass('show');
  }
});
online_mobile_accessories_btn.on('click', function(e) {
  e.preventDefault();
  jQuery('html, body').animate({scrollTop:0}, '300');
});

window.addEventListener('load', (event) => {
    jQuery(".preloader").delay(1000).fadeOut("slow");
});

//Sticky Header
jQuery(window).scroll(function() {
    var online_mobile_accessories_data_sticky = jQuery(' .head_bg').attr('data-sticky');

    if (online_mobile_accessories_data_sticky == 1) {
      if (jQuery(this).scrollTop() > 1){  
        jQuery('.head_bg').addClass("sticky-head");
      } else {
        jQuery('.head_bg').removeClass("sticky-head");
      }
    }
});

//Preloader
function online_mobile_accessories_preloderFunction() {
  setTimeout(function() {           
  var pageTop = document.getElementById("page-top"); 
  if (pageTop) { 
    pageTop.scrollIntoView(); 
  }
      
  $('#ctn-preloader').addClass('loaded');  
  // Once the preloader has finished, the scroll appears 
  $('body').removeClass('no-scroll-y');

  if ($('#ctn-preloader').hasClass('loaded')) {
    // It is so that once the preloader is gone, the entire preloader section will removed
    $('#preloader').delay(1000).queue(function() {
      $(this).remove();
      
      // If you want to do something after removing preloader:
      online_mobile_accessories_afterLoad();
    });
  }
  }, 3000);
}
function online_mobile_accessories_afterLoad() {
    // After Load function body!
}

// Slider title
jQuery(function($){
  $('.slider .slider_box .slider-main-title').each(function(){
    var w = $(this).text().trim().split(' ');
    $(this).html(w[0] + " <span class='head_words'>" + w.slice(1,4).join(' ') + "</span> " + w.slice(4).join(' '));
  });
});