
var ucRotator = new Class(
{
	Implements: Options, 
	
	options: 
    {  	
	w:680,
	h:150
    },
    
    initialize: function(options)
    {
    	this.setOptions(options);
    	this.container = $(this.options.container);
    	this.list = this.container.getElement('ul');
    	//this.list.shuffle();
    	this.links = $$('#'+this.options.container+' li');
    
    	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,
    		'text-indent':'-99999px',
    		'display':'block'
    		});
    		/*item.addEvents({
    			'mouseover' : function() {
    				$clear(this.timer);
    			}.bind(this),
    			'mouseout' : function() {
    				this.timer = this.start();
    			}.bind(this)
    			
    		});*/
    	}.bind(this));
    	
    	this.timer = this.start();
    },
    
    start:function(){
    	return this.scroll.periodical(3000,this);
    },
    
    scroll: function() {
    	var index = this.index
    	
    	this.index++;
    	
    	var margin = -this.height;
    	var fx = new Fx.Tween(this.list);
    	fx.start('margin-top',margin).addEvent('onComplete', function(){
			var parent = this.links[index].dispose();
			this.list.grab(parent);
			this.list.setStyles({
				'margin-top':0
			});
    	}.bind(this));
    	
    	if(this.index >= (this.links.length)) {
    		this.index = 0;
    	}	
    }
});


window.addEvent('domready', function() 
	{
		new ucRotator({
			container: 'rotator',
			cfg:{
				w:680,
				h:150
			}
		});		
});