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

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

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

      if ( ! shiftKey && tabKey && jungle_safari_lastEl === jungle_safari_activeEl ) {
        e.preventDefault();
        jungle_safari_firstEl.focus();
      }

      if ( shiftKey && tabKey && jungle_safari_firstEl === jungle_safari_activeEl ) {
        e.preventDefault();
        jungle_safari_lastEl.focus();
      }
    } );
  }
  jungle_safari_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");
  });
});

// Title Color
jQuery(document).ready(function () {
  jQuery("#banner .banner-content .banner-title").each(function () {
    var t = jQuery(this).text().trim();
    var splitT = t.split(" ");
    var newText = "";

    for (var i = 0; i < splitT.length; i++) {
      if (i === 0) {
        newText += "<span class='highlight-text'>" + splitT[i] + "</span> ";
      } else if (i === splitT.length - 2) {
        newText += "<span class='highlight-text'>" + splitT[i] + "</span> ";
      } else {
        newText += splitT[i] + " ";
      }
    }

    jQuery(this).html(newText.trim());
  });
});

//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 jungle_safari_sticky = document.querySelector('.copyright-sticky');
  if (!jungle_safari_sticky) return;

  var jungle_safari_scrollTop = window.scrollY || document.documentElement.scrollTop;
  var jungle_safari_windowHeight = window.innerHeight;
  var jungle_safari_documentHeight = document.documentElement.scrollHeight;

  var jungle_safari_isBottom = jungle_safari_scrollTop + jungle_safari_windowHeight >= jungle_safari_documentHeight - 100;

  if (jungle_safari_scrollTop >= 100 && !jungle_safari_isBottom) {
    jungle_safari_sticky.classList.add('copyright-fixed');
  } else {
    jungle_safari_sticky.classList.remove('copyright-fixed');
  }
});

/* Progress Bar */
document.addEventListener("DOMContentLoaded", function () {
    const jungle_safari_progressBar =
        document.getElementById("jungle_safari_elemento_progress_bar");
    if (!jungle_safari_progressBar) return;
    window.addEventListener("scroll", function () {
        const jungle_safari_scrollTop =
            document.documentElement.scrollTop || document.body.scrollTop;
        const jungle_safari_height =
            document.documentElement.scrollHeight -
            document.documentElement.clientHeight;
        const jungle_safari_scrolled =
            (jungle_safari_scrollTop / jungle_safari_height) * 100;
        jungle_safari_progressBar.style.width =
            jungle_safari_scrolled + "%";
    });
});
