var t_slide = {
    init: function() {
        this.transition_time = 1000;
        this.delay = 2000
        
        // hide all images
        var imgs = $$('#t_slide img');
        if(imgs) {
            imgs.each(function(el) {
                el.setStyle('opacity', 0);
            });
        }
        
        var blocks = $$('.part');
        
        this.total_images = 4;
        this.total_blocks = 3;
        
		this.images = new Array();
        blocks.each(function(el, index) {
			this.images[index] = $$('#' + el.getProperty('id') + ' img');
			this.images[index][0].setStyle('opacity', 1);
        }.bind(this));
    },
    
    rotate_images: function(image) {
        // loop for each time
        (function() { 
            this.rotate_image(0, image); 
        }.bind(this)).delay(this.transition_time);
        
        (function() { 
            this.rotate_image(1, image); 
        }.bind(this)).delay(this.transition_time * 1.5);
        
        (function() { 
            this.rotate_image(2, image);
        }.bind(this)).delay(this.transition_time * 2);
        
        var delay = (this.transition_time * 2.5) + this.delay;
        
        // trigger next rotate
        (function() { 
            this.rotate_images(this.get_next(image));
        }.bind(this)).delay(delay);
    },
    
    get_next: function(current) {
        return (this.total_images - 1 == current) ? 0 : current + 1;
    },
    
    rotate_image: function(block, image) {
    
        // current image
        o_image = image - 1;
        if(o_image == -1) {
            o_image = this.total_images - 1;
        }
        
        var c_fx = new Fx.Styles(this.images[block][o_image], {
            duration: this.transition_time,
            wait: false
        });
        c_fx.start({'opacity': 0});
        
        var fx = new Fx.Styles(this.images[block][image], {
            duration: this.transition_time,
            wait: false
        });
        fx.start({'opacity': 1});
    }
}
