/*
 * Simple News Ticker
 * Copyright 2010 Martino Flynn
 * Author Mike Ruschak
 *
 * Version 1.0
 *
 * This plugin allows for pagination through lots of items.
 */

(function($) {
	$.fn.newsticker = function(options) {
		var defaults = {
			speed: 600,
			delay: "7s"
		};

		var options = $.extend(defaults, options);
		var newsPosts = $("#headline", this);
		var newsPostsChildren = newsPosts.children();
		var totalPosts = newsPostsChildren.length;
		var postNum = 0;

		newsPostsChildren.not(":first").hide();
	
		newsPosts.everyTime(options.delay, function() {
		
		newsPosts.find(":eq(" + postNum + ")").fadeOut(options.speed, function() {
				
				if (postNum == (totalPosts-1)) {
					postNum = 0;
				} else {
					postNum += 1;
				}
				
				newsPosts.find(":eq(" + postNum + ")").fadeIn(options.speed);
			});
		});
	};
})(jQuery);
