jQuery.fn.extend({
	startTicker: function(tickerbox, interval) {
		this.data("index",0)
		this.data("tickerbox", tickerbox)
		// progress bar
		progress = $("#"+tickerbox.attr("id")+"-progress")
		this.data("progress", progress)
		progress.html("1 / "+this.find("li").length)
		// hide all listitems
		if(typeof interval == 'undefined')
			interval = 15000
		elements = this.find("li")
		elements.each(function(){
			//$(this).animate({opacity:0},0)
			$(this).hide()
		})
		tickerbox.html($(elements[0]).html())
		a = this
		setInterval('a.switchTicker()', interval)
	},
	
	switchTicker: function() {
		elements = this.find("li")
		index = this.data("index")
		tickerbox = this.data("tickerbox")
		index += 1
		if(index >= elements.length)
			index = 0
		tickerbox.animate({opacity:'toggle'},500, function(){
			tickerbox.html($(elements[index]).html())
			tickerbox.animate({opacity:'toggle'},500)			
		})
		// update progress bar
		this.data("progress", progress)
		progress.html((index+1)+" / "+this.find("li").length)
		this.data("index",index)
	}
})

