var Ticker = new Class({
	setOptions: function(options) {
		this.options = Object.extend({
			speed: 600,
			delay: 5000,
			direction: 'horizontal',
			onComplete: Class.empty,
			onStart: Class.empty
		}, options || {});
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		this.items = this.el.getElements('li');
		var w = 0;
		var h = 0;
		if(this.options.direction.toLowerCase()=='horizontal') {
			h = this.el.getSize().y;
			this.items.each(function(li,index) {
				w += li.getSize().x;
			});			
		} 
		this.el.setStyles({
			width: w,
			height: h,
			'z-index': 4
		});
		this.morph = new Fx.Morph(this.el,{
			duration:this.options.speed,
			onComplete:function() {
				var i = (this.current==0)?this.items.length:this.current;
				this.items[i-1].injectInside(this.el);
				this.el.setStyles({
					'margin-left':0,
					'margin-top':0
				});
			}.bind(this)
		});
		this.current = 0;
		this.next.bind(this).delay(this.options.delay+this.options.speed);
	},
	next: function() {
		this.current++;
		if (this.current >= this.items.length)
			this.current = 0;
		var pos = this.items[this.current];
		this.morph.start({
			'margin-left': -pos.getSize().x			
		});
		this.next.bind(this).delay(this.options.delay+this.options.speed);
	}
});
