// This uses jquery.jfeed.js
// http://www.hovinne.com/blog/index.php/2007/07/15/132-jfeed-jquery-rss-atom-feed-parser-plugin
// blog_url is URL of blog feed (must be content-type of text/xml)
// div_id is id of div to overwrite (caller HTML is responsible for 
//   contents before feed returns e.g. "Loading...")
// verbose_articles = number of articles with descriptions
// total_articles = max number of articles to show altogether (verbose or otherwise)
function render_blog(blog_url, div_id, verbose_articles, total_articles) {
	$(document).ready(function() {
	    jQuery.getFeed({
	        url: blog_url,
	        success: function(feed) {
	
	            var html = '<ul class="blog_result">';
	                    
	            for(var i = 0; i < feed.items.length && i < total_articles; i++) {
	            
	                var item = feed.items[i];
	                
	                link = ''
	                + '<a href="'
	                + item.link
	                + '">'
	                + item.title
	                + '</a>';
	
	                date = getBlogDate(new Date(item.updated));
	                date_html = '<span class="blog_date">' + date + '</span>';
	                
	                if (i < verbose_articles) {
		                html += '\n<li class="blog_verbose">';
	                	html += link + date_html + ' - ';

	                    html += '<span class="blog_text">'
	                    + item.description
	                    + '</span>';
	                } else {
	                	html += '\n<li class="blog_normal">'
	                    html += link + date_html
	                }
	                
	                html +='</li>'
	            }
	            
	            html += '</ul>';
	            jQuery(div_id).replaceWith(html);
	        }
	    });
	 });
}

function getBlogDate(date_obj) {
	return date_obj.getShortMonthName() + ' ' + 
		date_obj.getDate() + ', ' +
		date_obj.getFullYear();
}

Date.prototype.getShortMonthName = function() {
	return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
	        'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][this.getMonth()]; 
}
