/* Call ajax server script to get list of posts from an RSS feed and insert into content */

function loadBlogList(rootPath, target, feedURL, blogURL, blogName, type, limit)
{
	var scriptPath = rootPath + '/ajax/ajax-feed.php';

	$('#' + target).oneTime(2000, function() { showWait(rootPath, target); });
	
	$.ajax({
		  type: 'POST',
		  url: scriptPath,
		  data: {
					feedURL: feedURL,
					blogURL: blogURL,
					blogName: blogName,
					feedType: type,
					feedLimit: limit
				},
		  success: function(data) {
					showResult(target, data);
					},
		  timeout: 10000,
		  error:	function(data) {
						showError(target, blogURL, blogName);
					}
		});
}

function showWait(rootPath, target)
{
	$('#' + target).removeClass('align-left');
	$('#' + target).addClass('align-centre');
	$('#' + target).html('<img src="' + rootPath + '/images/ajax-loader-orange.gif" alt="Loading..." />');
	$('#' + target).stopTime();
}

function showResult(target, res)
{
	$('#' + target).stopTime();
	$('#' + target).removeClass('align-centre');
	$('#' + target).addClass('align-left');
	$('#' + target).html(res);
}

function showError(target, blogURL, blogName)
{
	$('#' + target).stopTime();
	$('#' + target).removeClass('align-centre');
	$('#' + target).addClass('align-left');
	$('#' + target).html('<ul><li>Please <a href="' + blogURL + '">visit the ' + blogName + '</a>.</li></ul>');
}

