var PhotoChanger = Class.create();
PhotoChanger.prototype = {
  items: new Array(),
  max: 0,
  actual: 0,
  initialize: function(obj) {
    this.items = obj.childElements();
    this.max = this.items.length;
    this.actual = 0;
    maxH = 0;
    maxW = 0;
    for(i=0;i<this.items.length;i++){
      this.items[i].hide();
      if(maxH<this.items[i].getHeight()){
        maxH = this.items[i].getHeight();
      }
      obj.setStyle({        
        height: maxH+'px'
      });
      this.items[i].setStyle({
        position: 'absolute'
      });
    }
    this.items[this.actual].show();
    obj = this;
    if(this.max > 1){
      this.next.delay(6, obj);    
    }
  },
  next:  function(obj){
    
    
    obj.old = obj.actual;
    
    obj.actual++;

    if(obj.actual >= obj.max){
      obj.actual = 0;
    }
    
    Effect.Fade(obj.items[obj.old], {duration: 3.0});
    Effect.Appear(obj.items[obj.actual], {duration: 3.0});
  
    
    obj.next.delay(6, obj);
  }
};

Event.observe(window, 'load', function(){
  $$('.photoChanger').each(function(o){
    new PhotoChanger(o);
  })  
});


