var recentPosts = new google.feeds.Feed("http://empoweringlives.tumblr.com/rss");
recentPosts.setNumEntries(10); //Max entries: 200
recentPosts.load(formatoutput);//calls the function to download posts

function formatoutput(result){
if (!result.error){
var thefeeds=result.feed.entries;
populateFeed(thefeeds);
}
else{//if error fetching feed, alert human readable error message
alert(result.error.message);
}
}

function populateFeed(thefeeds){
//populate the starting divs


var title = ""; //store the post title in ‘title’
var theUrl = "";//store the URL in ‘theUrl’
var post_id = "";//store post id by exploding 'theUrl' below

for (var i=0; i<thefeeds.length; i++){

theUrl = thefeeds[i].link; //get the URL of the post
title = thefeeds[i].title; //get the title of the post
post_id = theUrl.split("/");

var divTag = document.createElement("div"); //create a new div
divTag.className = "recentPostDiv"; //set the new div’s class
divTag.innerHTML = "<dl><dt class='borderbtm'><a href='/posts/" + post_id[4] + "'>" + title + "</a></dt></dl>"; //construct the HTML
document.getElementById('recentPostsContainer').appendChild(divTag); //add the info to your HTML
}
}

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+'">Loading feed...</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 monthdate=new Date(datestr);
	var daydate=new Date(datestr);
	var yeardate=new Date(datestr);
	
var months = new Array(12);
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";
var days = new Array(31);
days[0] = "1st";
days[1] = "2nd";
days[2] = "3rd";
days[3] = "4th";
days[4] = "5th";
days[5] = "6th";
days[6] = "7th";
days[7] = "8th";
days[8] = "9th";
days[9] = "10th";
days[10] = "11th";
days[11] = "12th";
days[12] = "13th";
days[13] = "14th";
days[14] = "15th";
days[15] = "16th";
days[16] = "17th";
days[17] = "18th";
days[18] = "19th";
days[19] = "20th";
days[20] = "21st";
days[21] = "22nd";
days[22] = "23rd";
days[23] = "24th";
days[24] = "25th";
days[25] = "26th";
days[26] = "27th";
days[27] = "28th";
days[28] = "29th";
days[29] = "30th";
days[30] = "31st";


var month_value = monthdate.getMonth();
var day_value = daydate.getDay();
var year_value = yeardate.getFullYear();

var display = months[month_value] + ' ' + days[day_value] + ', ' + year_value + ' <br /><br />';

return "<span style='color: #999999;font-family: helvetica,arial;font-size: 10px;margin-bottom:10px;font-weight: normal;'><br />"+display+"</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="<ul>"
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)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""
rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li>"
}
rssoutput+="</ul>"
this.feedcontainer.innerHTML=rssoutput
}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}

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

