Slideshow JavaScript: Slide Change

function gtJSUI_changeSlide(myButton) {

  var direction = myButton.getAttribute('data-direction');
  var slideShow = myButton.getAttribute('data-slideshow');

  if ((direction == 'prev') || (direction == 'next')) {
    var slideSet = document.getElementById('gtSlideshowSet_' + slideShow);
    var oldID = slideSet.getAttribute('data-current-slide');
    var newID = Math.abs(oldID) + (direction == 'prev' ? -1 : 1);

    if (newID > (slideSet.children.length -1)) { newID = 0; }
    if (newID < 0) { newID = (slideSet.children.length -1); }

    var oldSlide = document.getElementById('gtSlideshowSlide_' + slideShow + '_' + oldID);
    var newSlide = document.getElementById('gtSlideshowSlide_' + slideShow + '_' + newID);

    if (oldSlide && newSlide) {
      oldSlide.style.display = 'none';
      newSlide.style.display = 'block';

      slideSet.setAttribute('data-current-slide', newID);

      document.getElementById('gtSlideshowStatus_' + slideShow).innerHTML = 'Slide ' + (newID + 1) + ' of ' + (slideSet.children.length);
    }

  }

}