google.load("feeds", "1") //Load Google Ajax Feed API (version 1)

function rssdisplayer(divid, url, feedlimit, showoptions) {
	this.showoptions = showoptions || ""; //get string of options to show ("date" and/or "description")
	var feedpointer = new google.feeds.Feed(url); //create new instance of Google Ajax Feed API
	feedpointer.setNumEntries(feedlimit); //set number of items to display

	document.write('<div id="' + divid + '"><p>Loading posts...</p></div>');
	this.feedcontainer = document.getElementById(divid);
	var displayer = this;
	feedpointer.load(function(r) {displayer.formatoutput(r)}); //call Feed.load() to retrieve and output RSS feed
}


rssdisplayer.prototype.formatdate = function(datestr) {
	var itemdate = new Date(datestr);
	var m_names = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
	return "<span>" + itemdate.getDate() + '-' + m_names[itemdate.getMonth()] + '-' + itemdate.getFullYear() + "</span>"
}


rssdisplayer.prototype.formatoutput = function(result) {
	if (!result.error) { //if RSS feed successfully fetched
		
		var thefeeds = result.feed.entries; //get all feed entries as a JSON array
		var rssoutput = "";
		
		for (var i=0; i<thefeeds.length; i++) { //loop through entries
			var itemtitle = "<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>";
			var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : "";
			var itemdescription=/description/i.test(this.showoptions)? ""+thefeeds[i].content : /snippet/i.test(this.showoptions)? ""+thefeeds[i].contentSnippet  : "";
			
			if (this.showoptions == 'date, description') {
				rssoutput += "<p class='date'>" + itemdate + "</p> <h1>" + itemtitle + '</h1>' + itemdescription;
			} else {
				rssoutput += "<p><span class='date'>" + itemdate + "</span>" + itemtitle + "</p>" + itemdescription;
			}
		} 
		
		rssoutput += "";
		this.feedcontainer.innerHTML = rssoutput;
		
	} else {}
}

//USAGE SYNTAX: new rssdisplayer("divid", "rssurl", numberofitems, "displayoptions")
//new rssdisplayer("adiv", "http://www.cssdrive.com/index.php/news/rss_2.0/", 5, "date, description")




function quickshow(id) {
	document.getElementById(id).style.display="";
}

function quickhide(id) {
	document.getElementById(id).style.display="none";
}
