var OverlayMove = {
    init: function() {
        this.addEventFunction();
        this.options = {}
        this.next_thumb = 1;
        
        this.options['ele'] = $$('div.thumb');
        this.options['txt_1'] = $('textTop');
        this.options['txt_2'] = $('textBottom');
        this.options['canvas'] = $('overlay');
        if(this.options['txt_2']) {
	        this.options['txt_2'].set('opacity', 0);
		
		
	        (function() {
    	        this.switchThumb(this.options['ele'][this.next_thumb]);
        	}.bind(this)).periodical(4000);
		}
    },
        
    addEventFunction: function() {
        $$('div.thumb').each(function(thumb) {
            /*thumb.addEvent('click', function() {
                this.switchThumb(thumb);
            }.bind(this));*/
        }.bind(this));
    },
    
    switchThumb: function(thumb) {
        this.options['ele'].setStyle('z-index', -2);
        var myFx = new Fx.Morph(this.options['canvas']);
        myFx.start({
            'top':thumb.getStyle('top'),
            'left':thumb.getStyle('left')
        }); 
        thumb.setStyle('z-index',1);
        
        var text = thumb.get('title');
        if(this.options['txt_1'].getStyle('opacity') == 0) {
            this.options['txt_1'].set('text', text);
            this.options['txt_2'].tween('opacity', 0);
            this.options['txt_1'].tween('opacity', 1);
        } else {
            this.options['txt_2'].set('text', text);
            this.options['txt_1'].tween('opacity', 0);
            this.options['txt_2'].tween('opacity', 1);
        }
        
        /*
        this.options['canvas'].tween('top', thumb.getStyle('top'));
        (function() {
            this.options['canvas'].tween('left', thumb.getStyle('left'));
            thumb.setStyle('z-index',1);
        }.bind(this)).delay(600);*/
        this.next_thumb = this.next_thumb + 1;
        if(this.next_thumb > this.options['ele'].length - 1) {
            this.next_thumb = 0;
        }
    }
    
}

window.addEvent('domready', function() {
//    var overlay_move = new OverlayMove();
    OverlayMove.init();
});

