var counter = -1;
var slides = [];

async function loadSlides()  {
  var slidei = 1;
  var sectioni = 1;

  sectionloop: while(true) {
    slidei = 1;
    slideloop: while(true) {
      const req = await fetch(`./slide/${sectioni}/${slidei}.html`);
      if(req.status != 200) {
        if(slidei == 1) break sectionloop;
        break slideloop;
      }
      slides.push(await req.text());
      slidei++;
    }
    sectioni++;
  }
  nextSlide();
}

loadSlides();

function nextSlide() {
  if(counter >= slides.length - 1) return;

  container.innerHTML = slides[++counter];
}

function previousSlide() {
  if(counter <= 0) return;

  container.innerHTML = slides[--counter];
}

document.body.addEventListener('click', nextSlide); 

document.addEventListener(
  "keydown",
  (event) => {
    if(event.key === "ArrowRight") {
      nextSlide();
      return;
    }
    if(event.key === "ArrowLeft") {
      previousSlide();
      return;
    }
  },
  false,
);

