text: window.addEventListener("load", () =>
  {
      document.getElementById("status-btn").addEventListener("click", loadGallery);
      loadGallery();
  });
  
  function loadGallery()
  {
      document.getElementById("status-btn").disabled = true;
      document.getElementById("status-btn").innerText = "Loading...";
  
      if (getQueryStringValue("id") === null || !isInteger(getQueryStringValue("id")))
      {
          document.getElementById("status-btn").innerText = "Error";
          return;
      }
  
      getJson("api.php/galleries/" + getQueryStringValue("id"))
          .then(json =>
          {
              addGalleryInfoToDom(json);
  
              const imageGrid = new InfiniteImageGrid(
                  document.getElementById("image-grid"), getQueryStringValue("id"));
              imageGrid.onStateChanged = state => onImageGridStateChanged(state);
  
              document.getElementById("status-btn").removeEventListener("click", loadGallery);
              document.getElementById("status-btn").addEventListener("click",
                  () => imageGrid.loadImages());
  
              imageGrid.loadImages();
          })
          .catch(() =>
          {
              document.getElementById("status-btn").disabled = false;
              document.getElementById("status-btn").innerText = "Error, Try Again?";
          });
  }
  
  function addGalleryInfoToDom(gallery)
  {
      document.title = gallery.name + " | Henry Hunt Photography";
      document.getElementById("gallery-info-name").innerHTML = gallery.name;
  
      if (gallery.description.length > 0)
      {
          document.getElementById("gallery-info-desc").innerHTML = gallery.description;
          document.getElementById("gallery-info").classList.add("gallery-info-long");
      }
  
      document.getElementById("gallery-info").style.display = "block";
  }
  
  function onImageGridStateChanged(state)
  {
      switch (state)
      {
          case "loading":
          {
              document.getElementById("status-btn").disabled = true;
              document.getElementById("status-btn").innerText = "Loading...";
              break;
          }
  
          case "load-more":
          {
              document.getElementById("status-btn").disabled = false;
              document.getElementById("status-btn").innerText = "Load More Images";
              break;
          }
  
          case "all-loaded":
          {
              document.getElementById("status-btn").innerText = "All Images Loaded";
              break;
          }
  
          case "error":
          {
              document.getElementById("status-btn").disabled = false;
              document.getElementById("status-btn").innerText = "Error, Try Again?";
              break;
          }
  
          default: break;
      }
  
      if ((state === "load-more" || state === "all-loaded") &&
          document.getElementById("image-grid").children.length > 0)
      {
          document.getElementById("image-grid").style.marginBottom = 40;
      }
  }