jQuery.fn.ticker = function(settings) {

	settings = jQuery.extend({
		speed: 30
	}, settings);
	
	return this.each(function() {

			function performScroll() {
				$strip.css({ left: position -= 0.65 });
				if (position < -items[currentIndex].width()) {
					items[currentIndex].appendTo(items[currentIndex].parent().get(0));
					currentIndex++;
					if (currentIndex >= items.length) {
						currentIndex = 0;
					}
					position = 0;
					$strip.css("left", 0);
				}
			}

			function getItemsWidth() {
				var itemsWidth = 0;
				$strip.find("li").each(function(li) {
					var item = jQuery(this, li);
					itemsWidth += item.width();
				});
				return itemsWidth;
			}
		
			var $strip = jQuery(this);
			$strip.addClass("ticker");
			
			var stripWidth = 0;
			var $mask = $strip.wrap("<div class='mask'>");
			var $tickercontainer = $strip.parent().wrap("<div class='ticker-container'>");								
			var containerWidth = $strip.parent().parent().width();
			var items = [];
			var itemsWidth = getItemsWidth();
			var currentIndex = 0;
			var position = 0;
			while (itemsWidth <= containerWidth * 2) {
				$strip.find("li").each(function(li) {
					var item = jQuery(this, li);
					item.clone().appendTo(item.parent().get(0));
				});
				//console.debug(containerWidth);
				itemsWidth = getItemsWidth();
			}
			
			$strip.find("li").each(function(li) {
				var item = jQuery(this, li);
				items.push(item);
				stripWidth += item.width();
			});

			$strip.width(stripWidth);
			setInterval(performScroll, settings.speed);
	});	
};
