jQuery(document).ready(function() {
	// Cache the ticker
	var ticker = jQuery("#recent-posts ul");

	// Hide the scrollbar
	ticker.css('overflow', 'hidden');

	// Animator function
	function animator(currentItem) {
		// Work out new anim duration
		var distance = currentItem.height();
		duration = (distance + parseInt(currentItem.css('marginTop'))) / 0.01;

		// Animate the first child of the ticker
		currentItem.animate({ marginTop: -distance }, duration, 'linear', function() {
			// Move current item to the bottom
			currentItem.appendTo(currentItem.parent()).css('marginTop', 6);

			// Recurse
			animator(currentItem.parent().children(':first'));
		});
	};

	// Start the ticker
	animator(ticker.children(":first"));

	// Set mouseenter
	ticker.mouseenter(function() {
		// Stop current animation
		ticker.children().stop();
	});

	// Set mouseleave
	ticker.mouseleave(function() {
		// Resume animation
		animator(ticker.children(":first"));
	});
});
