$(document).ready(function() {
  //  mark first
  $('.gallery-image').first().addClass('first-image');
  //  mark last
  $('.gallery-image').last().addClass('last-image');
  //  show first image
  $('.first-image').addClass('current-image');

  //  show next image
  $('#image-paging-forward').click(function() {
    var current = $('.current-image');
    //  hide current
    current.toggleClass('current-image');

    //  show next
    if (!current.hasClass('last-image')) {
      current.next('.gallery-image').toggleClass('current-image');
    }
    else {
      $('.first-image').toggleClass('current-image');
    }

    return false;
  });

  //  show previous image
  $('#image-paging-back').click(function() {
    var current = $('.current-image');
    //  hide current
    current.toggleClass('current-image');

    //  show previous
    if (!current.hasClass('first-image')) {
      current.prev('.gallery-image').toggleClass('current-image');
    }
    else {
      $('.last-image').toggleClass('current-image');
    }

    return false;
  });

});


