var Ticker = Class.create();
Ticker.prototype = {
	sources: $A(),
	current: null,
	interval: null,
	current: null,
	initialize: function(source, options) {
		this.source = $(source);
		this.options = Object.extend({
			updateRate: 2, 
			duration: 0.5,
			sourceselect: 'li'
		}, options || {});

		Element.cleanWhitespace(this.source);
		this.sources = $(this.source).select(this.options.sourceselect);
		var sh = this.source.getDimensions().height;
		var maxh = 0;
		this.sources.each(function(el) {
			var eh = el.getDimensions().height;
			sh -= eh;
			maxh = Math.max(maxh,eh);
			el.hide();
		}.bind(this));
		this.source.setStyle({height: (sh+maxh) + 'px'});
		
		this.start();
	},
	shownext: function() {
		if(this.current==null) {
			this.current=0;
			this.show();
		} else {
			this.hide();
			this.current++;
			if(this.current >= this.sources.size()) this.current=0;
			this.show();
		}
	},
	getCurrElement: function() {
		return this.sources[this.current];
	},
	show: function() {
		new Effect.Appear(this.getCurrElement(), this.options);
	},
	hide: function() {
		this.getCurrElement().hide();
	},
	start: function() {
		this.shownext();
		this.interval = new PeriodicalExecuter(this.shownext.bind(this), this.options.updateRate);
	},
	stop: function() {
		this.interval.stop();
	}
};

