// JavaScript Document
// http://www.quirksmode.org/dom/toc.html
// http://code.google.com/apis/ajaxfeeds/documentation/

// usage: 
// get a key from http://code.google.com/apis/ajaxfeeds/signup.html
//
// put the following in the head of the target document
/*
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAErLdnOLOpyGRGST73N1Z1xSLKJJB4muuuRc5w4eSq79-rx4hShTUAL5QAopB686QAqpomg9Wm4hyrg"></script>
*/
// add an empty div with an id of feedlist
//
// optionally populate the empty div with fallback content if js is disabled

google.load("feeds", "1");

function initialize() {
  var feed = new google.feeds.Feed("http://blog.runningimp.co.uk/feeds/posts/default/");
  feed.setNumEntries(4);
  feed.load(function(result) {
	if (!result.error) {
		
	  // abort if no posts in blog
	  if (result.feed.entries.length == 0)
	  	return;
		
	  var container = document.getElementById("news_feed_box");
	  
	  if (container == null)
	  	return;
	  
	  var header = document.createElement('p');
	  header.className += "news_header";
	  header.appendChild(document.createTextNode("LATEST NEWS"));
	  container.appendChild(header);

	  var postlist = document.createElement('ul');
  	  postlist.className += "fp_list";	  
	  container.appendChild(postlist);
	  
	  for (var i = 0; i < result.feed.entries.length; i++)
	  {
		var entry = result.feed.entries[i];

		var postlistitem = document.createElement('li');

		var postlink = document.createElement('a');
		postlink.appendChild(document.createTextNode(entry.title));

		postlistitem.appendChild(postlink);
		postlink.href = entry.link;
		
		postlist.appendChild(postlistitem);
	  }
	  
	  // add update link
/*	  var updateA = document.createElement('a');
	  updateA.href = "/newsletter.aspx";
      updateA.appendChild(document.createTextNode("Click here to receive"));
	  updateA.appendChild(document.createElement('br'));
	  updateA.appendChild(document.createTextNode("newsletter updates"));*/
	  
	  var updateP = document.createElement('p');
	  updateP.className += "update";
//	  updateP.appendChild(updateA);
	  
	  container.appendChild(updateP);
	  

	}
  });
}

google.setOnLoadCallback(initialize);