function showPopup() {
  let popup = document.getElementById('popup');

  // -------------- randomize POPUP BG -----------------
  // let popupBg = document.getElementById('popup-bg');
  // const images = [
  //   'image/tombol/RM2.jpg',
  //   'image/tombol/RM4.jpg',
  //   'image/tombol/RM8.jpg',
  //   'image/tombol/RM10.jpg'
  // ];
  // const randomIndex = Math.floor(Math.random() * images.length);
  // const selectedImage = images[randomIndex];
  // popupBg.src = selectedImage;

  popup.classList.add('show');
}

const tile1 = document.getElementById("tile1");
const tile2 = document.getElementById("tile2");
const tile3 = document.getElementById("tile3");
const tile4 = document.getElementById("tile4");

tile1.addEventListener("click", function () {
  tile2.style.pointerEvents = "none";
  tile3.style.pointerEvents = "none";
  tile4.style.pointerEvents = "none";
  showPopup();
}, { once: true });
tile2.addEventListener("click", function () {
  tile1.style.pointerEvents = "none";
  tile3.style.pointerEvents = "none";
  tile4.style.pointerEvents = "none";
  showPopup();
}, { once: true });
tile3.addEventListener("click", function () {
  tile1.style.pointerEvents = "none";
  tile2.style.pointerEvents = "none";
  tile4.style.pointerEvents = "none";
  showPopup();
}, { once: true });
tile4.addEventListener("click", function () {
  tile1.style.pointerEvents = "none";
  tile3.style.pointerEvents = "none";
  tile2.style.pointerEvents = "none";
  showPopup();
}, { once: true });

function animateGift(giftClass) {
  $('.' + giftClass).addClass("animation-gift");

  setTimeout(function () {
    $('.' + giftClass).removeClass("animation-gift");
  }, 800);
}
$(document).ready(function () {
  function startAnimationLoop() {
    animateGift('gift-1');
    setTimeout(function () {
      animateGift('gift-2');
      setTimeout(function () {
        animateGift('gift-3');
        setTimeout(function () {
          animateGift('gift-4');
          setTimeout(startAnimationLoop, 850);
        }, 850);
      }, 850);
    }, 850);
  }
  startAnimationLoop();
});
