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

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

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

      if ( ! shiftKey && tabKey && master_study_lite_lastEl === master_study_lite_activeEl ) {
        e.preventDefault();
        master_study_lite_firstEl.focus();
      }

      if ( shiftKey && tabKey && master_study_lite_firstEl === master_study_lite_activeEl ) {
        e.preventDefault();
        master_study_lite_lastEl.focus();
      }
    } );
  }
  master_study_lite_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");
  });
});

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

  var master_study_lite_scrollTop = window.scrollY || document.documentElement.scrollTop;
  var master_study_lite_windowHeight = window.innerHeight;
  var master_study_lite_documentHeight = document.documentElement.scrollHeight;

  var master_study_lite_isBottom = master_study_lite_scrollTop + master_study_lite_windowHeight >= master_study_lite_documentHeight - 100;

  if (master_study_lite_scrollTop >= 100 && !master_study_lite_isBottom) {
    master_study_lite_sticky.classList.add('copyright-fixed');
  } else {
    master_study_lite_sticky.classList.remove('copyright-fixed');
  }
});
/* Progress Bar */
document.addEventListener("DOMContentLoaded", function () {
    const master_study_lite_progressBar =
        document.getElementById("master_study_lite_elemento_progress_bar");
    if (!master_study_lite_progressBar) return;
    window.addEventListener("scroll", function () {
        const master_study_lite_scrollTop =
            document.documentElement.scrollTop || document.body.scrollTop;
        const master_study_lite_height =
            document.documentElement.scrollHeight -
            document.documentElement.clientHeight;
        const master_study_lite_scrolled =
            (master_study_lite_scrollTop / master_study_lite_height) * 100;
        master_study_lite_progressBar.style.width =
            master_study_lite_scrolled + "%";
    });
});
