// Menu
function home_repair_service_openNav() {
  jQuery(".sidenav").addClass('show');
}
function home_repair_service_closeNav() {
  jQuery(".sidenav").removeClass('show');
}

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

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

      if ( ! shiftKey && tabKey && home_repair_service_lastEl === home_repair_service_activeEl ) {
        e.preventDefault();
        home_repair_service_firstEl.focus();
      }

      if ( shiftKey && tabKey && home_repair_service_firstEl === home_repair_service_activeEl ) {
        e.preventDefault();
        home_repair_service_lastEl.focus();
      }
    } );
  }
  home_repair_service_keepFocusInMenu();
} )( window, document );

// scroll
jQuery(document).ready(function () {
	jQuery(window).scroll(function () {
	    if (jQuery(this).scrollTop() > 0) {
	        jQuery('#scrollbutton').fadeIn();
	    } else {
	        jQuery('#scrollbutton').fadeOut();
	    }
	});
	jQuery(window).on("scroll", function () {
	   document.getElementById("scrollbutton").style.display = "block";
	});
	jQuery('#scrollbutton').click(function () {
	    jQuery("html, body").animate({
	        scrollTop: 0
	    }, 600);
	    return false;
	});
});

// preloader
jQuery(function($){
  setTimeout(function(){
    $(".frame").delay(1000).fadeOut("slow");
  });
});

// homepage sidebar
jQuery(document).ready(function () {
  function home_repair_service_search_loop_focus(element) {
    var home_repair_service_focus = element.find('select, input, textarea, button, a[href]');
    var home_repair_service_firstFocus = home_repair_service_focus[0];  
    var home_repair_service_lastFocus = home_repair_service_focus[home_repair_service_focus.length - 1];
    var KEYCODE_TAB = 9;

    element.on('keydown', function home_repair_service_search_loop_focus(e) {
      var isTabPressed = (e.key === 'Tab' || e.keyCode === KEYCODE_TAB);

      if (!isTabPressed) { 
        return; 
      }

      if ( e.shiftKey ) /* shift + tab */ {
        if (document.activeElement === home_repair_service_firstFocus) {
        home_repair_service_lastFocus.focus();
          e.preventDefault();
        }
        } else /* tab */ {
        if (document.activeElement === home_repair_service_lastFocus) {
          home_repair_service_firstFocus.focus();
          e.preventDefault();
        }
      }
    });
  }

  jQuery('.toggle-btn a').click(function(){
    jQuery(".header-sidebar").addClass('show');
    home_repair_service_search_loop_focus(jQuery('.header-sidebar'));
  });

  jQuery('.header-sidebar .close-pop a').click(function(){
    jQuery(".header-sidebar").removeClass('show');
  });
});

// Video Popup
(function( $ ) {
    $(document).ready(function(){
        $('#openBtn').on('click', function() {
          $('#videoOverlay').css('display', 'flex');
        });
        $('.close-btn').on('click', function() {
          $('#videoOverlay').hide();
        });
    });
})( jQuery );

/*sticky copyright*/
window.addEventListener('scroll', function() {
  var home_repair_service_sticky = document.querySelector('.copyright-sticky');
  if (!home_repair_service_sticky) return;

  var home_repair_service_scrollTop = window.scrollY || document.documentElement.scrollTop;
  var home_repair_service_windowHeight = window.innerHeight;
  var home_repair_service_documentHeight = document.documentElement.scrollHeight;

  var home_repair_service_isBottom = home_repair_service_scrollTop + home_repair_service_windowHeight >= home_repair_service_documentHeight - 100;

  if (home_repair_service_scrollTop >= 100 && !home_repair_service_isBottom) {
    home_repair_service_sticky.classList.add('copyright-fixed');
  } else {
    home_repair_service_sticky.classList.remove('copyright-fixed');
  }
});

/* Progress Bar */
document.addEventListener("DOMContentLoaded", function () {
    const home_repair_service_progressBar =
        document.getElementById("home_repair_service_elemento_progress_bar");
    if (!home_repair_service_progressBar) return;
    window.addEventListener("scroll", function () {
        const home_repair_service_scrollTop =
            document.documentElement.scrollTop || document.body.scrollTop;
        const home_repair_service_height =
            document.documentElement.scrollHeight -
            document.documentElement.clientHeight;
        const home_repair_service_scrolled =
            (home_repair_service_scrollTop / home_repair_service_height) * 100;
        home_repair_service_progressBar.style.width =
            home_repair_service_scrolled + "%";
    });
});

