var Ticker = Class.create();
Ticker.prototype = {
	messages: new Array(),
	counter: 0, interval: 0, current: 0,
	target: null, source: null,
	initialize: function(target, source, options) {
		this.target = $(target); 
		this.source = $(source);
		this.options = Object.extend({
				updateRate: 2, 
				duration: 0.5,
				sourceselect: 'li',
				targettag: 'div',
				targetoptions: {
					'style' : 'background-color:#FFFFFF'
				}
			}, options || {});

		Element.cleanWhitespace(this.source);
		$(this.source).select(this.options.sourceselect).each(function(sel) {
		   this.messages.push(sel.innerHTML);
		}.bind(this));  

//		this.start();
	},
	setCurrent: function(n) {
		if(n!=this.current) {
			this.counter = n;
			this.stop();
			if(this.counter == this.messages.length){ this.counter = 0;}
			if(this.counter < 0){ this.counter=this.messages.length;}
			this.start();
		}
	},
	shownext: function() {
		var el = new Element(this.options.targettag,this.options.targetoptions);
		el.update(this.messages[this.counter]);
		el.hide();
		this.target.update('').insert(el);
		this.current = this.counter++;
		new Effect.Appear(el, this.options);
		if(this.counter == this.messages.length){ this.counter = 0;}
	},
	start: function() {
		if(this.interval==0) {
			this.shownext();
			this.interval = new PeriodicalExecuter(this.shownext.bind(this), this.options.updateRate);
		}
	},
	stop: function() {
		if(this.interval.stop) this.interval.stop();
		this.interval = 0;
	}
};
function updateThumb() {
	var e = $('outliner');
	var c = $('imag'+myticker.current);
	var d = c.getDimensions();
	var f = c.cumulativeOffset();	
	var s = {left: f.left+'px', top: f.top+'px', width: d.width +'px', height: d.height +'px'};
	if(e.visible()) {
		new Effect.Morph(e,{style: s, duration: 0.5});
	} else {
		e.setStyle(s);
		e.show();
	}
}
function jumpThumb(el) {
	myticker.setCurrent(el.target.getAttribute('rel'));
}
