(function($) {
	$.fn.extend({
		newsFlipper: function() {
			var current = 0;
			var items = [];
			var paused = false;
			
			function next() {
				items[current].hide();
				current = (current + 1) % items.length;
				items[current].fadeIn();
			}
			
			function prev() {
				items[current].hide();
				current = (current - 1) % items.length;
				items[current].fadeIn();
			}

			function flip() {
				if (!paused) { next(); }
			}

			return this.each(function() {
				// iterate over the items and add them to the items array
				$(this).children().each(function() {
					$(this)
						.css({ display: 'inline', 'background-color': 'white' })
						.mouseover(function() { paused = true;  })
						.mouseout(function()  { paused = false; })
						.hide();
					items.push($(this));
				});
				current = items.length - 1;
				flip();
				setInterval(flip, 5000);
			});
		}
	});
})(jQuery);
