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

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

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

      if ( ! shiftKey && tabKey && business_association_lastEl === business_association_activeEl ) {
        e.preventDefault();
        business_association_firstEl.focus();
      }

      if ( shiftKey && tabKey && business_association_firstEl === business_association_activeEl ) {
        e.preventDefault();
        business_association_lastEl.focus();
      }
    } );
  }
  business_association_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-sec .banner-text-box .banner-title").each(function() {
    var business_association_t = jQuery(this).text().trim();
    var business_association_splitT = business_association_t.split(" ");

    if (business_association_splitT.length >= 1) {
      var business_association_beforeLastTwo = business_association_splitT.slice(0, -1).join(" ");
      var business_association_lastTwo = business_association_splitT.slice(-1).join(" ");
      var business_association_newText = business_association_beforeLastTwo + ' <span class="title-text">' + business_association_lastTwo + '</span>';
      jQuery(this).html(business_association_newText);
    } else {
      jQuery(this).html(business_association_t);
    }
  });
});

// Member Slider
jQuery('document').ready(function(){
  var owl = jQuery('#members-section .owl-carousel');
    owl.owlCarousel({
    margin: 50,
    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,
      },
      1000: {
        items: 3,
        margin: 10,
      },
      1200: {
        items: 3,
      }
    },
    mouseDrag: true
  });
});