var playerPromise = new Promise(function(resolve) {
  // Load the YouTube API script
  var tag = document.createElement('script');
  tag.src = "https://www.youtube.com/iframe_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  // Callback function for YouTube iFrame API readiness
  window.onYouTubeIframeAPIReady = function() {
    var yTplayer = new YT.Player('video-container', {
      videoId: videoId,
      playerVars: {
        autoplay: 0,
        modestbranding: 1,
        rel: 0,
        showinfo: 0,
        controls: 0
      }
    });
  };
});

// function isElementInViewport(element) {
//   var rect = element.getBoundingClientRect();
//   return (
//     rect.top >= 0 &&
//     rect.left >= 0 &&
//     rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
//     rect.right <= (window.innerWidth || document.documentElement.clientWidth)
//   );
// }

// function checkIfElementInView() {
//   var videoContainer = document.getElementById('video-container');

//   if (isElementInViewport(videoContainer)) {
//     playerPromise.then(function(player) {
//       player.playVideo();  // Play the video when in view
//     });

//     // Remove the scroll event listener once the element is in view (if desired)
//     window.removeEventListener('scroll', checkIfElementInView);
//   }
// }

// // Attach the scroll event listener to constantly check if the element is in view
// window.addEventListener('scroll', checkIfElementInView);