
/*  Class: ImageSlideShow
    -----------------------------------------------  */
    if (typeof ImageSlideShow != 'undefined') throw("ImageSlideShow is already defined.");
    ImageSlideShow = Class.create();
    ImageSlideShow.prototype = {

    // Attributes
      name: "ImageSlideShow",
      version: "0.01",
      element: null,
      list: null,
      index: 0,
      delay: 0,

    // Methods
      initialize: function(element) {
        Object.extend(this, arguments[1] || {});

        if (element != null) {
          this.element = $(element);
          
          // Pick a random initial image
          this.index = Math.floor((Math.random() * this.list.length) + 1);
          this.preloadNext();
          
          if (this.list != null) {
            this._next();
            setTimeout(function() {
              setInterval(this.next.bind(this), 12000);
              this.next();
            }.bind(this), this.delay);
          }
        }
      },
      preloadNext: function() {
        var preloader = new Image(10, 10);
        preloader.src = this.list[this.index];
      },
      next: function() {
        new Effect.Morph(this.element, {style:{opacity: "0"}, duration: 0, afterFinish: function() {
          this._next();
          new Effect.Morph(this.element, {style:{opacity: "1"}, duration: 1});
        }.bind(this)});
      },
      _next: function() {
        if (this.index <= 0 || this.index >= this.list.length) {
          this.index = 0;
        }
        this.element.setStyle({
          "backgroundImage": "url(" + this.list[this.index] + " )"
        });
        this.index++;
          
        this.preloadNext();
      }
    };
    var slideshow;
    document.observe("dom:loaded", function() {
      new ImageSlideShow($("photos-1"), { list: [
        "/assets/images/photos/0-1-rosie-and-joseph.jpg",
        "/assets/images/photos/0-1-ball-soccer.jpg",
        "/assets/images/photos/0-1-board-work.jpg",
        "/assets/images/photos/0-1-drumer.jpg",
        "/assets/images/photos/0-1-fife.jpg"
      ]});
      new ImageSlideShow($("photos-2"), { list: [
        "/assets/images/photos/0-1-joel.jpg",
        "/assets/images/photos/0-1-kids-singing.jpg",
        "/assets/images/photos/0-1-kids-to-bus.jpg",
        "/assets/images/photos/0-1-mcguffey.jpg",
        "/assets/images/photos/0-1-pre-k.jpg"
      ], delay: 4000});
      new ImageSlideShow($("photos-3"), { list: [
        "/assets/images/photos/0-1-science-boys.jpg",
        "/assets/images/photos/0-1-seniors.jpg",
        "/assets/images/photos/0-1-teamwork.jpg",
        "/assets/images/photos/0-1-volleyball.jpg",
        "/assets/images/photos/0-1-working.jpg"
      ], delay: 8000});
    });
