$(document).ready(function()
{
	initNewsTicker($("#ticker"));
});



function initNewsTicker(box)
{
	var ticker = box;
	setTimeout(function()
	{
		ticker.children().filter("li").each(function()
		{
			var dt = $(this),
			container = $("<div>");
			dt.appendTo(container);
			dt.prependTo(container);
			container.appendTo(ticker);
		});
				
		ticker.css("overflow", "hidden");
		function animator(currentItem)
		{
			var distance = currentItem.height();
			duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.010;
			currentItem.animate({ marginTop: -distance }, duration, "linear", function()
			{
				currentItem.appendTo(currentItem.parent()).css("marginTop", 0);
				animator(currentItem.parent().children(":first"));
			}); 
		};

		animator(ticker.children(":first"));
		ticker.mouseenter(function()
		{
			ticker.children().stop();
		});
		ticker.mouseleave(function()
		{
			animator(ticker.children(":first"));
		});
		//delay before the reel starts
	}, 1000);
}