﻿/*
Change these variables and add a div with the id of "feed" in order to use this
*/
var NUM_ELEMENTS = 5;
var FEED_URL = "http://feeds.feedburner.com/jtac";
var SHOW_DATES = 'true';  // use 'true' and 'false'
var TITLE = "";

/******************   DO NOT EDIT BELOW THIS LINE  ***********************/

function GetRelativeTime(value) {
	var dt = new Date(value);
	var now = new Date();
	var secs = parseInt((now.getTime() - dt.getTime()) / 1000);

	if (secs < 60) { return "less than a minute ago" }
	else {
		if (secs < 120) { return "about a minute ago" }
		else {
			if (secs < (60 * 60)) { return (parseInt(secs / 60)).toString() + " minutes ago" }
			else {
				if (secs < (120 * 60)) { return "about an hour ago" }
				else {
					if (secs < (24 * 60 * 60)) { return "about " + (parseInt(secs / 3600)).toString() + " hours ago" }
					else {
						if (secs < (48 * 60 * 60)) { return "1 day ago" }
						else { return (parseInt(secs / 86400)).toString() + " days ago" }
					}
				}
			}
		}
	}

}
;

google.load("feeds", "1");

function initialize() {
	var feed = new google.feeds.Feed(FEED_URL);
	feed.setNumEntries(NUM_ELEMENTS);
	feed.load(function(result) {
		if (!result.error) {
			var container = document.getElementById("feed");
			var docTitle = document.createElement("div");
			docTitle.id = "feedTitle";
			docTitle.appendChild(document.createTextNode(TITLE));
			container.appendChild(docTitle);
			for (var i = 0; i < result.feed.entries.length; i++) {
				var entry = result.feed.entries[i];
				var attributes = ["title", "link", "publishedDate"];
				var feedElement = document.createElement("a");
				feedElement.href = entry["link"];
				feedElement.target = '_blank';
				feedElement.appendChild(document.createTextNode(entry["title"]));
				var div = document.createElement("div");
				div.id = "feedElement";
				div.appendChild(feedElement);
				container.appendChild(div);
				if (SHOW_DATES == 'true') {
					var date = document.createElement("div");
					date.id = "publishedDate";
					date.appendChild(document.createTextNode(GetRelativeTime(entry["publishedDate"])));
					container.appendChild(date);
				}
			}
		}
	});
}
google.setOnLoadCallback(initialize);