YUI.add("scanroe", function (Y) {
  
  Y.ScanRoe = {

    init: function () {
      
      var machineImages = Y.all(".machine_images");

      if (machineImages.size() > 0) {
        machineImages.each(function (node) {
          new Y.PhotoViewer({container: node});
        });
      }
  
    }

  };

}, "1.0.0", {requires: ["node", "photo_viewer"]});

YUI.add("photo_viewer", function (Y) {

  var PhotoViewer = function (config) {
    PhotoViewer.superclass.constructor.apply(this, arguments);
  };

  PhotoViewer.NAME = "PhotoViewer";
  PhotoViewer.ATTRS = {};

  Y.extend(PhotoViewer, Y.Base, {

    initializer: function (options) {
      this.container = options.container;
      this.currentImage = this.container.one(".machine_current_image > img");
      this.thumbnails = this.container.all(".machine_image_thumbs li");
      this.thumbnails.on("click", this.showPhoto, this);
    },

    showPhoto: function (ev) {
      var selectedImage = ev.currentTarget;

      this.thumbnails.removeClass("current");
      selectedImage.addClass("current");
      this.currentImage.set("src", selectedImage.one("img").get("src"));
    }

  });

  Y.PhotoViewer = PhotoViewer;

}, "1.0.0", {requires: ["base"]});

