(function($) { 
$.fn.ticker = function(){
	var o = this;
	initTicker = function(_obj){
		el = $('ul', _obj)[0];
		el.items = $('li', el);
		el.items.not(":eq(0)").hide().end();
		el.currentitem = 0;
		$('ul', _obj).show();
		doTick(o, 0);
	};
	doTick = function(_obj, _dir){
		el = $('ul', _obj)[0];
		$(el.items[el.currentitem]).hide();
		el.currentitem += _dir;
		if (el.currentitem<0) el.currentitem = el.items.size()-1;
		if (el.currentitem>=el.items.size()) el.currentitem = 0;
		$(el.items[el.currentitem]).show();
		$('.counter', _obj).html((el.currentitem+1)+' OF '+el.items.size());
	};
	setTimer = function(_obj, delay){
		el = $('ul', _obj)[0];
		el.timer = setInterval( function() { doTick(_obj, 1) }, delay);
	};
	stopTimer = function(_obj, delay){
		el = $('ul', _obj)[0];
		clearInterval(el.timer);
	};
	this.each(function(){ initTicker(this); });
	$('.prev', this).click(function(){ stopTimer(o); doTick(o, -1); });
	$('.next', this).click(function(){ stopTimer(o); doTick(o, 1); });
};
})(jQuery);
$(document).ready(function(){
	$('#news-ticker').ticker();
	setTimer($('#news-ticker'), 3000);
});


