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

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

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

      if ( ! shiftKey && tabKey && visa_consulting_service_lastEl === visa_consulting_service_activeEl ) {
        e.preventDefault();
        visa_consulting_service_firstEl.focus();
      }

      if ( shiftKey && tabKey && visa_consulting_service_firstEl === visa_consulting_service_activeEl ) {
        e.preventDefault();
        visa_consulting_service_lastEl.focus();
      }
    } );
  }
  visa_consulting_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");
  });
});

// Header search
jQuery('document').ready(function($){
  $('.main-search span a').click(function(){
    $(".searchform_page").slideDown(500);
    visa_consulting_service_Keyboard_loop($('.searchform_page'));
  });

  $('.visa-consulting-service-close a').click(function(){
    $(".searchform_page").slideUp(500);
  });
});

var visa_consulting_service_Keyboard_loop = function (elem) {
  var visa_consulting_service_tabbable = elem.find('select, input, textarea, button, a').filter(':visible');

  var visa_consulting_service_firstTabbable = visa_consulting_service_tabbable.first();
  var visa_consulting_service_lastTabbable = visa_consulting_service_tabbable.last();
  visa_consulting_service_firstTabbable.focus();

  /*redirect last tab to first input*/
  visa_consulting_service_lastTabbable.on('keydown', function (e) {
    if ((e.which === 9 && !e.shiftKey)) {
      e.preventDefault();
      visa_consulting_service_firstTabbable.focus();
    }
  });

  /*redirect first shift+tab to last input*/
  visa_consulting_service_firstTabbable.on('keydown', function (e) {
    if ((e.which === 9 && e.shiftKey)) {
      e.preventDefault();
      visa_consulting_service_lastTabbable.focus();
    }
  });

  /* allow escape key to close insiders div */
  elem.on('keyup', function (e) {
    if (e.keyCode === 27) {
      elem.hide();
    };
  });
};

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

  var visa_consulting_service_scrollTop = window.scrollY || document.documentElement.scrollTop;
  var visa_consulting_service_windowHeight = window.innerHeight;
  var visa_consulting_service_documentHeight = document.documentElement.scrollHeight;

  var visa_consulting_service_isBottom = visa_consulting_service_scrollTop + visa_consulting_service_windowHeight >= visa_consulting_service_documentHeight - 100;

  if (visa_consulting_service_scrollTop >= 100 && !visa_consulting_service_isBottom) {
    visa_consulting_service_sticky.classList.add('copyright-fixed');
  } else {
    visa_consulting_service_sticky.classList.remove('copyright-fixed');
  }
});