// JavaScript Document
// http://www.quirksmode.org/dom/toc.html
// http://code.google.com/apis/ajaxfeeds/documentation/

google.load("feeds", "1");

function initialize() {
  var feed = new google.feeds.Feed("http://blog.churchers.co.uk/feeds/posts/default/-/Company%20Matters");
  feed.setNumEntries(10);
  feed.load(function(result) {
	if (!result.error) {
	  var container = document.getElementById("newsSide");
	  
	  // empty out all children
	  if ( container.hasChildNodes() )
	  {
		while ( container.childNodes.length >= 1 )
		{
			container.removeChild( container.firstChild );       
		} 
	  }	   
	  	  
	  var header = document.createElement('h2');
	  header.appendChild(document.createTextNode("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);
	  }
	}
  });
}

google.setOnLoadCallback(initialize);