function smoothAdd($,id, text)
{

	var el = $('#' + id);

	var h = el.height();

	el.css({
		height:   h,
		overflow: 'hidden'
	});

	var ulPaddingTop    = parseInt(el.css('padding-top'));
	var ulPaddingBottom = parseInt(el.css('padding-bottom'));

	el.prepend('<li>' + text + '</li>');

	var first = $('li:first', el);
	var last  = $('li:last',  el);

	var foh = first.outerHeight();

	var heightDiff = foh - last.outerHeight();

	var oldMarginTop = first.css('margin-top');

	first.css({
		marginTop: 0 - foh,
		position:  'relative',
		top:       0 - ulPaddingTop
	});

	last.css('position', 'relative');

	el.animate({ height: h + heightDiff }, 1500)

	first.animate({ top: 0 }, 250, function() {
		first.animate({ marginTop: oldMarginTop }, 1000, function() {
			last.animate({ top: ulPaddingBottom }, 250, function() {
				last.remove();

				el.css({
					height:   'auto',
					overflow: 'visible'
				});
			});
		});
	});
}

var t ;

jQuery(function() {
	
	var complete = 
		function(data) {
			//	Find the ticker-widget unordered list
			var widget= jQuery('#ticker-widget');

			//	Split the array according to the newline character
    			var posts= response.responseText.split("\n");

			//	Remove the last blank element of the array
			//	that is inserted because of the newline character
			//	at the end of the last full element of the array
			posts.pop();

			//	Add the links to the unordered list
			for ( var i = 0; i<2; i++ )
				widget.prepend( '<li>'+posts[ i]+'</li>');

			//	Add a new link every five seconds
			setInterval( function() { smoothAdd(jQuery,'ticker-widget',posts[++i % posts.length]); }, 5000 );
		}

	//	Request the news posts
	//	Todo: Add the post category as a name-value get query pair
	var response = jQuery.ajax({
	    	url: "http://www.madsystems.com/wp-content/themes/minianimalism/news.php",
    		dataType: "text",
    		success : complete
	});
});


