var ImageViewer = Class.create({
  
  initialize: function(images) {
    this.images = images;
    this.currentImage = images[0];
    this.currentImage.toggle();
  },
  
  showProductImage: function(image) {
    this.currentImage.toggle();
    this.currentImage = image;
    this.currentImage.toggle();      
  },
  
  nextImage: function() {
    this.showProductImage(this.images[this._incrementIndex()]);
  },
  
  previousImage: function() {
    this.showProductImage(this.images[this._decrementIndex()]);        
  },
  
  zoomImage: function () {
    this.currentImage.onclick();
  },
  
  _incrementIndex: function() {
    imagesIndex = this.images.indexOf(this.currentImage);
    if (imagesIndex == this.images.size() - 1) {
      imagesIndex = 0;
    } else {
      imagesIndex ++;
    }
    return imagesIndex;        
  },
  
  _decrementIndex: function() {
    imagesIndex = this.images.indexOf(this.currentImage);
    if (imagesIndex == 0) {
      imagesIndex = this.images.size() - 1;
    } else {
      imagesIndex --;
    }
    return imagesIndex;        
  }
  
});