var Diaporama = Class.create();
var effectDuration = 0.7;
var showDelay = 3000;
var fps_effect = 15.0;

Diaporama.prototype =  {
    images            : [],
    current_image_idx : 0,

    initialize: function() {
        if (!document.getElementsByTagName){ return; }

        var fadeContainers = $$('.diaporama');
        for(fcpt= 0; fcpt < fadeContainers.size(); fcpt++) {
            var fadeContainer = fadeContainers[fcpt];

            fadeContainer.immediateDescendants().each(function(d) {
                if (d.nodeName == 'DIV' && d.firstChild && d.firstChild.nodeName == 'IMG') {
                    d.id = 'fondu_' + this.images.size();
                    this.images.push(d);
                }
            }.bind(this));


            setInterval(function() {
                new Effect.Fade(
                        this.images[this.current_image_idx].id, 
                        { duration: effectDuration, from:1.0, to:0.0, fps: fps_effect }
                );
                this.current_image_idx++;
                if (this.current_image_idx >= this.images.length ) this.current_image_idx = 0;
                new Effect.Appear(
                    this.images[this.current_image_idx].id, 
                    { duration: effectDuration, from:0.0, to:1.0, fps: fps_effect }
                );
            }.bind(this), showDelay);
            //this.images[0].show();
            new Effect.Appear(
                this.images[0].id, 
                { duration: effectDuration, from:0.0, to:1.0 }
            );
        }
    }

}
function initDiaporama() { myDiaporama = new Diaporama(); }
Event.observe(window, 'load', initDiaporama, false);

