window.onload = function () {

  var modal = document.getElementById("imgModal");
  var modalImg = document.getElementById("modalImg");
  var closeBtn = document.getElementsByClassName("close")[0];

  var images = document.getElementsByClassName("thumb");

  for (var i = 0; i < images.length; i++) {
    images[i].onclick = function () {
      modal.style.display = "block";
      modalImg.src = this.src;
    };
  }

  closeBtn.onclick = function () {
    modal.style.display = "none";
  };

  modal.onclick = function (e) {
    if (e.target === modal) {
      modal.style.display = "none";
    }
  };

};
