    /*
JS/jQUERY FOR LAYOUT 560
Gabe @ Build Your Firm
5/5/2026
*/


// FIXED NAVBAR ON SCROLL
$(function() {
  var navpos = $('#headerNavbar').offset();
  // 1. function to set fixed nav
  function fixNav() {
    if ($(window).scrollTop() > navpos.top) {
      $('#headerNavbar').addClass('fixed-top');
      var $headerHeight = $('#headerNavbar').outerHeight() + "px";
      $('header').css({'paddingBottom': $headerHeight});
    } else {
      $('#headerNavbar').removeClass('fixed-top');
      $('header').css({'paddingBottom': 0});
    }
  }
  // 2. set fixed nav on page load
  fixNav();
  // 3. set fixed nav on page scroll
  $(window).bind('scroll', function() {
    fixNav();
  });
});



document.addEventListener( 'DOMContentLoaded', () => {

    // Handle high contrast toggle button click
    document.querySelector( '#hc-toggle' ).addEventListener( 'click', function() {
      if ( !document.body.classList.contains( 'hcm' ) ) {
        document.body.classList.add( 'hcm' );
        byf_set_cookie( 'byf_hc_mode', '1', 14 );
      } else {
        document.body.classList.remove( 'hcm' );
        byf_set_cookie( 'byf_hc_mode', '0', 14 );
      }
      this.blur();
    });
  
    // Set high contrast mode if set in cookie
    function byf_set_hc_mode() {
      let byf_hc_mode = byf_get_cookie( 'byf_hc_mode' );
      if ( byf_hc_mode == 1 ) {
        document.body.classList.add( 'hcm' );
      }
    }
  
    // Check for cookie on page load
    byf_set_hc_mode();
  
  
    // Generic get cookie
    function byf_get_cookie( cname ) {
      var name = cname + '=';
      var decodedCookie = decodeURIComponent(document.cookie);
      var ca = decodedCookie.split( ';' );
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
          c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
        }
      }
      return '';
    }
  
    // Generic set cookie
    function byf_set_cookie( cname, cvalue, exdays ) {
      var d = new Date();
      d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
      var expires = 'expires=' + d.toUTCString();
      document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
    }
  
  
    // Event listeners for updating 'aria-expanded' property for dropdowns when using keyboard navigation
    document.querySelectorAll( '.nav-item' ).forEach( navlink => {
  
      navlink.addEventListener( 'click', function(e) {
        if ( navlink.parentNode.classList.contains( 'show' ) ) {
          return;
        }
        byf_set_aria( navlink );
      });
  
      navlink.addEventListener( 'keyup', function(e) {
        if ( e.keyCode != 9 || navlink.getAttribute( 'aria-expanded' ) == 'true' ) {
          return;
        }
        byf_set_aria( navlink );
      });
  
    });
  
    // Helper function to update aria-expanded property
    function byf_set_aria( navlink ) {
      document.querySelectorAll( 'button.nav-link' ).forEach( link => {
        link.setAttribute( 'aria-expanded', 'false' );
      });
  
      if ( navlink.tagName == 'BUTTON' ) {
        navlink.setAttribute( 'aria-expanded', 'true' );
      }
    }
    
    
    
    
  });