// 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.turbine-efficiency.com/feeds/posts/default");
  feed.setNumEntries(10);
  feed.load(function(result) {
	if (!result.error) {
		
	  // abort if no posts in blog
	  if (result.feed.entries.length == 0)
	  	return;
		
	  var container = document.getElementById("feedlist");
	  
	  // 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("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);
	  }
	}
  });
}

google.setOnLoadCallback(initialize);