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

  Y.PhotoViewer = Y.Base.create("PhotoViewer", Y.Base, [], {

    initializer: function (options) {
      this.N = options.containerNode;

      this.currentImage =  this.N.one(".machine_current_image");
      this.currentImage.on("click", this.showFull, this);

      this.thumbnails = this.N.all(".machine_image_thumbs li");
      this.thumbnails.on("click", this.showPhoto, this);
    },

    showFull: function () {
      var imageURL = this.currentImage.get("src"), modal, full;

      full = this.currentImage.data("full");
      if (full) {
        imageURL = full;
      }

      modal = new Y.ModalPresenter({content: "<img src='" + imageURL + "'>", 
                                    classNames: "image_full"});
      modal.show();
    },

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

      this.thumbnails.removeClass("current");
      selectedImage.addClass("current");

      full = selectedImage.one("img").data("full");

      this.currentImage.set("src", selectedImage.one("img").get("src"));
      this.currentImage.data("full", full);
    }

  }, {ATTRS: {}});

}, "1.0.0", {requires: ["node", "node-data", "base", "presenters:modal"]});

