
(function($) {
$.fn.newsTicker = $.fn.newsticker = function(delay)
{
	delay = delay || 4000;
	initTicker = function(tickElements)
	{
		stopTicker(tickElements);
		tickElements.items = $("li", tickElements);
		//tickElements.items.not(":eq(0)").hide().end();
		tickElements.currentitem = 0; //start by
		startTicker(tickElements);
	};
	startTicker = function(tickElements)
	{
		tickElements.tickfn = setInterval(function() { tick(tickElements) }, delay)
	};
	stopTicker = function(tickElements)
	{
		clearInterval(tickElements.tickfn);
	};
	pauseTicker = function(tickElements)
	{
		tickElements.pause = true;
	};
	resumeTicker = function(tickElements)
	{
		tickElements.pause = false;
	};
	tick = function(tickElements)
	{
		// don't run if paused
		if(tickElements.pause) return;
		// pause until animation has finished
		tickElements.pause = true;
		// hide current item
		$(tickElements.items[tickElements.currentitem]).fadeOut("slow",function()
			{
				$(this).hide();
				tickElements.currentitem = ++tickElements.currentitem % (tickElements.items.size());
				$(tickElements.items[tickElements.currentitem]).fadeIn("slow",function()
					{
						$(tickElements.items[tickElements.currentitem]).css("display","block");
                                                tickElements.pause = false;
					}
				);
			}
		);
	};

	this.each(function(){
            if(this.nodeName.toLowerCase()!= "ul") return;
		initTicker(this);
            }
	).hover(function(){	
			pauseTicker(this);
		},function(){
			resumeTicker(this);
		}
	);
	return this;
};

})(jQuery);