
(function($) {

	$.fn.newsScroller = $.fn.newsscroller = function()
	{
		initScroller = function(el)
		{	
			stopScroller(el);
	
			el.wrapper = $("> div.newsScrollerWrapper", el)[0];
			el.list = $("> ul", el.wrapper)[0];
			
			el.origionalListWidth  = el.list.offsetWidth;

			if(el.origionalListWidth >= (el.wrapper.offsetWidth - 10))
			{
				$("> li", el.list).clone().appendTo($(el.list));
				$(el).hover(
					function(){ pauseScroller(el); },
					function(){ resumeScroller(el); }
				);
				startScroller(el); 
			};
		};
		startScroller = function(el)
		{
			el.tick = setInterval(function() { doScroll(el) }, 60);
		};
		stopScroller = function(el)
		{
			clearInterval(el.tick);
		};
		pauseScroller = function(el)
		{
			el.pause = true;
		};
		resumeScroller = function(el)
		{
			el.pause = false;
		};
		doScroll = function(el)
		{
			if(el.pause) return;
		
			var leftPos = el.list.style.left;
			leftPos = (leftPos == null || leftPos == '')? 0 : leftPos.replace('px', '');
			leftPos = ((leftPos - 1) <= (el.origionalListWidth * -1))? 0 : leftPos - 1;
			
			el.list.style.left = leftPos + 'px';
		};
		
		initScroller( this );

		return this;
	}

})(jQuery);