jQuery(document).ready(function($) {
    // Handle hover and focus events for menu items with children
    $('.menu-item-has-children').on('mouseenter focusin', function() {
        $(this).children('.sub-menu').css({'opacity': '1', 'pointer-events': 'auto'});
    });

    // Handle mouseleave and blur events for menu items with children
    $('.menu-item-has-children').on('mouseleave focusout', function() {
        $(this).children('.sub-menu').css({'opacity': '0', 'pointer-events': 'none'});
    });

    // Ensure submenus are shown when their children receive focus
    $('.menu-item-has-children > .sub-menu > .menu-item > a').on('focus', function() {
        $(this).parents('.sub-menu').css({'opacity': '1', 'pointer-events': 'auto'});
    });

    // Ensure submenus are hidden when focus leaves their children
    $('.menu-item-has-children > .sub-menu > .menu-item > a').on('blur', function() {
        $(this).parents('.sub-menu').css({'opacity': '0', 'pointer-events': 'none'});
    });
});
// Chatbot Keyboard nav.
document.addEventListener('DOMContentLoaded', function() {
    // Wait for the chatbot script to load and initialize
    const checkChatbotLoaded = setInterval(function() {
      const chatbotButton = document.querySelector('.sc-open-icon'); 
      if (chatbotButton) {
        clearInterval(checkChatbotLoaded);
        
        // Make the button focusable
        chatbotButton.setAttribute('tabindex', '0');
        
        // Add event listener for keyboard navigation on the chatbot button
        chatbotButton.addEventListener('keydown', function(event) {
          if (event.key === 'Enter' || event.key === ' ') {
            // Open the chat window if Enter or Space is pressed
            chatbotButton.click();
          }
        });
  
        // Add event listener to close the chat window with Escape key
        document.addEventListener('keydown', function(event) {
          if (event.key === 'Escape') {
            // Close the chat window
            const closeButton = document.querySelector('.sc-header--close-button'); 
            if (closeButton) {
              closeButton.click();
            }
          }
        });
  
        // Handle skip link functionality
        const skipLink = document.getElementById('skip_chat');
        skipLink.addEventListener('keydown', function(event) {
          if (event.key === 'Enter' || event.key === ' ') {
            // Focus and open the chatbot button on Enter or Space keypress
            event.preventDefault();
            chatbotButton.focus();
            chatbotButton.click();
          }
        });
      } 
    }, 100);
  });   
  document.addEventListener('DOMContentLoaded', function() {
    const skipBanner = document.querySelector('.skip-banner');
    const mainContent = document.body; // Change this if the main content is wrapped differently
  
    const adjustPageContent = () => {
      if (window.getComputedStyle(skipBanner).visibility === 'visible') {
        mainContent.style.paddingTop = skipBanner.offsetHeight + 'px';
      } else {
        mainContent.style.paddingTop = '0px';
      }
    };
  
    // Use MutationObserver to detect style changes within the skip banner
    const observer = new MutationObserver(adjustPageContent);
    observer.observe(skipBanner, { attributes: true, attributeFilter: ['style'] });
  
    // Monitor focus within and outside the banner to adjust the layout
    skipBanner.addEventListener('focusin', adjustPageContent);
    skipBanner.addEventListener('focusout', adjustPageContent);
  
    // Initial adjustment if needed
    adjustPageContent();
  });



