var adRotate = new Class(
{
	Implements: Options, 
	
	options: {  	
	w:340,
	h:300
    },
    
    initialize: function(options)
    {
    	this.setOptions(options);
    	this.container = $(this.options.container);
    	this.list = this.container.getElement('ul');
    	this.links = $$('#'+this.options.container+' li').setStyles({'position':'absolute','display':'none','opacity':0});
    	    
    	this.cfg = this.options.cfg;
    	this.width = this.cfg.w;
    	this.height = this.cfg.h;
    	
    	this.index = 0;
    	var tmp = this.container.getStyles();
    	this.container.setStyles(tmp);
    	this.container.setStyles({
    		'height':this.height,
    		'width':this.width,
    		'overflow':'hidden',
    		'position':'relative'
    	});
    	    	
    	this.links.each(function(item){
    		item.setStyles(tmp);
    		item.setStyles({
    		'width':this.width,
    		'height':this.height
    		});
    	}.bind(this));
    	
    	this.timer = this.start();
    },
    
    start:function(){
    	this.scroll();
    	return this.scroll.periodical(6000,this);
    },
    
    scroll: function() {
    	var fx = new Fx.Tween(this.links[this.index],{duration:500});
    	this.links[this.index].tween('display','block');
    	fx.start('opacity',1).addEvent('onComplete', function(){
			var previous = this.links[this.index].dispose();
			previous.setStyle('opacity',0);
			this.list.grab(previous);
    	}.bind(this));
    	
    	this.index++;
    	
    	if(this.index >= (this.links.length)) {
    		this.index = 0;
    	}
    }
});


window.addEvent('domready', function() 
	{
		new adRotate({
			container: 'ad',
			cfg:{
				w:340,
				h:200
			}
		});		
});