function showLeaveComments() {
  document.getElementById('add-comments-body').style.display='block';
  document.getElementById('leave-comments').style.cursor='default';
}



function showNextPic() {
  cur = $("#img" + curPic);
  curPic += 1;
  if (curPic > maxPic) {
    curPic = 1;
  }
  next = $("#img" + curPic);
  adjustPics(cur, next);

  if (curPic >= curThumb + numThumb) {
    nextThumbnail();
    checkThumbButtons();
  } else if (curPic == 1) {
    resetThumbnails();
    checkThumbButtons();
  }
}

function showPrevPic() {
  cur = $("#img" + curPic);
  curPic -= 1;
  if (curPic < 1) {
    curPic = maxPic;
  }
  next = $("#img" + curPic);
  adjustPics(cur, next);
  checkThumbs(curPic);

}

function showPic(next) {
  cur = $("#img" + curPic);
  curPic = next;
  next = $("#img" + curPic);
  adjustPics(cur, next);
}

function adjustPics(cur, next) {
  cur.fadeOut(150, function() {next.fadeIn(200)});
}


function nextThumbnail() {
  if (curThumb + numThumb > maxPic) {
    return;
  }
  remove = $("#thumb" + curThumb);
  add = $("#thumb" + (curThumb + numThumb));
  curThumb += 1;
  adjustThumbs(remove, add);
  checkThumbButtons();
}

function prevThumbnail() {
  if (curThumb <= 1) {
    return;
  }
  curThumb -= 1;
  remove = $("#thumb" + (curThumb + numThumb));
  add = $("#thumb" + curThumb);
  adjustThumbs(remove, add);
  checkThumbButtons();
}

function adjustThumbs(remove, add) {
  remove.hide();
  add.fadeIn("fast");
}

function checkThumbButtons() {
  if (curThumb <= 1) {
    $("#prevThumb").addClass("inactive");
  } else {
    $("#prevThumb").removeClass("inactive");
  }
  if (curThumb + numThumb > maxPic) {
    $("#nextThumb").addClass("inactive");
  } else {
    $("#nextThumb").removeClass("inactive");
  }
}

function resetThumbnails() {
  for (i = 1; i <= maxPic; i++) {
    if (i <= numThumb) {
      $("#thumb" + i).show();
    } else {
      $("#thumb" + i).hide();
    }
  }
  curThumb = 1;
}
