	
	/**
	 * jquery.ticker.js 
	 * Creates a seamless stock ticker from Ajax feed
	 * Developer: matt@matthewdunham.com
	 * Date Created: 04/06/2010
	 */

	(function($){
	
		$.fn.extend({ 
			
			ticker: function(options) {
				
				var defaults = {
					ajaxFile: '/feeds/quotes',
					speed: 2000,
					requote: 15000,
					hoverStop: true
				};
				
				var options = jQuery.extend(defaults, options);
				var obj = $(this);
				obj.append('<div></div>');
				var intVar = null;
				
				if (options.hoverStop) {
					obj.find('div').hover(function(t){
						if (intVar===null) intVar = setInterval(slide,30);
						else { clearInterval(intVar); intVar = null; }
					});
				}
				
				var slide = function() {
					var wid = 0;
					obj.find('ul').each(function(){
						wid = (wid + $(this).width());
						var left = $(this).css('left');
						left = parseInt(left.replace('px',''));
						if (isNaN(left)===true) left = 0;
						left = left - 1;
						if (left<=parseInt('-'+$(this).width())) {
							$(this).siblings().css('left','1px');
							$(this).remove();
							getAjax();
						}
						$(this).stop(false,true).css('left',left+'px');
						
					});	 
					obj.find('div').css('width',(wid)+'px');
				}
				var getAjax = function() {
					$.ajax({
						type: "GET",
						url: options.ajaxFile,
						dataType: "html",
						success: function(html) {
							obj.find('div').html(obj.find('div').html()+html);
							if (intVar==null) intVar = setInterval(slide,30);
						}
					});
				}
				getAjax();
				getAjax();
			}
		});
	})(jQuery);
