(function($) {
    $.fn.newsTicker = $.fn.newsticker = function(delay) {
    	delay = delay || 5000;
    	initTicker = function(el) {
    		stopTicker(el);
    		el.items = $("li", el);
    		el.items.not(":eq(0)").hide().end();
    		el.currentitem = 0;
    		startTicker(el);
    	};
    	startTicker = function(el) {
    		el.tickfn = setInterval(function() { doTick(el) }, delay)
    	};
    	stopTicker = function(el) {
    		clearInterval(el.tickfn);
    	};
    	doTick = function(el) {
    		if(el.pause) return;
    		el.pause = true;
    		$(el.items[el.currentitem]).animate({left:'0'}, 1).animate({top:'+=' + (20 + ($(el.items[el.currentitem]).height() / 2))},1000, function() {
    				$(this).hide();
    				el.currentitem = ++el.currentitem % (el.items.size());
    				$(el.items[el.currentitem]).animate({top:'0'}, 1);
                    $(el.items[el.currentitem]).animate({top:'-=' + (20 + ($(el.items[el.currentitem]).height() / 2))},1);
                    $(el.items[el.currentitem]).fadeIn();
                    $(el.items[el.currentitem]).animate({top:'+=' + (20 + ($(el.items[el.currentitem]).height() / 2))},1000,function(){el.pause = false;});
    			}
    		);
    	};
    	this.each( function() {if(this.nodeName.toLowerCase()!= "ul") return;initTicker(this);}).addClass("newsticker");
    	return this;
    };
})(jQuery);

$(document).ready(function(){
    $("#ticker").newsticker();
});
