google.load("feeds", "1"); //Load Google Ajax Feed API (version 1)

function rssdisplayer(divid, url, feedlimit, showoptions){
	this.showoptions=showoptions || ""; 
	var feedpointer=new google.feeds.Feed(url);
	feedpointer.setNumEntries(feedlimit);
	document.write('<div id="'+divid+'">Loading feed...</div>');
	this.feedcontainer=document.getElementById(divid);
	var displayer=this;
	feedpointer.load(function(r){displayer.formatoutput(r)}); 
	}
	
	
	rssdisplayer.prototype.formatdate=function(datestr){
	var itemdate=new Date(datestr);
	return "<span style='color:#959595'>Date Posted: "+itemdate.toDateString()+"</span>";
	}
	
	
	rssdisplayer.prototype.formatoutput=function(result){
	if (!result.error){ 
		var thefeeds=result.feed.entries; 
		var rssoutput="";
		for (var i=0; i<thefeeds.length; i++){ 
		var itemtitle="<a href='"+thefeeds[i].link+"' target='_blank'><h2 style='font-size:20px;margin-top:8px;color: #2B7BB9;'>" + thefeeds[i].title + "</h2></a>";
		var itemdate=/date/i.test(this.showoptions)? "<br>"+this.formatdate(thefeeds[i].publishedDate) : "";
		var itemdescription=/description/i.test(this.showoptions)? "<span style='margin-bottom:8px;display:inline-block;'>"+thefeeds[i].content+"</span>" : /snippet/i.test(this.showoptions)? "<span style='margin-bottom:8px;display:inline-block;'>"+thefeeds[i].contentSnippet+"</span>"  : "";
		rssoutput += itemtitle + itemdescription + itemdate;
		}
		
		this.feedcontainer.innerHTML=rssoutput;				
	}
	else{
		alert("Error fetching feeds: "+result.error.message);
	}
}
