// JavaScript Document
var Ticker = new Class({
	setOptions: function(options) {
		this.options = Object.extend({
			speed: 1000,
			delay: 5000,
			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;
		this.items.each(function(li,index) {
			w += li.getSize().size.x
		});
		this.el.setStyles({
			position: 'absolute',
			top: 0,
			left: 0,
			width: w
		});
		this.periodical = 
		this.fx = new Fx.Styles(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.setStyle('left',0);
			var log = new Element('p').setText('inject: ' + this.el.getStyle('margin-left'));
			log.injectInside('Log');
		}.bind(this)});
		this.current = 0;
		this.next();
	},
	next: function() {
		this.current++;
		if (this.current >= this.items.length) this.current = 0;
		this.fx.start({
			top: this.items[this.current].offsetTop,
			left: -this.items[this.current].offsetLeft
		});
		this.next.bind(this).delay(this.options.delay);
	}
});