var Carousel = new Class({
    
    Implements                    : Options,
    
    options                       :
    {
        'speed'                   : 6000
    },
    
    initialize                    : function(container,options)
    {
        this.setOptions(options);
        this.images        			= $(container).getElements('img');
        this.count        			= this.images.length;
        this.current    			= 0;
        this.previous     			= this.count - 1;
        this.loadImage();
        if (this.count > 1) {
            this.loop = this.loadImage.periodical(this.options.speed,this);
        }
    },
    
    loadImage                    : function()
    {    
    
        this.images.setStyle('z-index',0);
        
        var previous    			= this.images[this.previous];
        var active         			= this.images[this.current];
        
        var dim						= active.getDimensions();
        
        active.setStyle('left',((148/2) - (dim.x / 2) + 1) + 'px');
        active.setStyle('top',((148/2) - (dim.y / 2) + 1) + 'px');
        
        previous.setStyle('z-index',1);
        
        var tween = new Fx.Tween(active);
        active.setStyle('z-index',2);

        tween.start('opacity',0,1).chain(function(){
            previous.setStyle('opacity',0);
        });
        
        this.previous = this.current;
        
        this.current++;
        if (this.current == this.count) this.current = 0;
        //console.log(active);
    }
    
});


