function cycleImages() {
    var images = $$('div.imageHolder').first().select('div.image');
    if (images.length > 1) {
        var delay = 6000;
        var currentDelay = delay;
        var fadeDuration = 1.2;
        var firstImage = images[0];
        images.each(function(image) {
            window.setTimeout(function() {
                this.fade({ duration: fadeDuration });
            } .bind(image), currentDelay);
            var nextImage = image.next('div.image');
            if (!nextImage) nextImage = firstImage;
            if (nextImage) {
                window.setTimeout(function() {
                    this.appear({ duration: fadeDuration });
                    var imageHeight = this.readAttribute('imageHeight');
                    if (!imageHeight) {
                        this.show();
                        imageHeight = this.down('img').getHeight();
                        this.writeAttribute('imageHeight', imageHeight);
                        this.hide();
                    }
                    var holder = $$('div.imageHolder').first();
                    var currentHeight = holder.getHeight();
                
                    new Effect.Tween(holder, currentHeight, imageHeight, { duration: (fadeDuration * .5) }, function(newHeight) {
                        this.setStyle({ height: newHeight + 'px' });
                    });
                    
                } .bind(nextImage), currentDelay);
            }
            currentDelay += delay;
        });
    };
    window.setTimeout(cycleImages, currentDelay);
}
Event.observe(window, 'load', function() {
    if ($$('div.imageHolder').first() == null) return;
    window.setTimeout(cycleImages, 100);

    var firstImage = $$('div.imageHolder').first().down('div.image img');
    if(firstImage != null) {
        $$('div.imageHolder').first().setStyle({ height: firstImage.getHeight() + 'px' });
    } else {
        $$('div.imageHolder').first().setStyle({ height: 'auto' });
    }
});

