/**
 * Loads a Google Search control and RSS Feed control.
 * 
 * @author bjackson
 */
GSearch.setOnLoadCallback(function ()
{
	// Create a search control
	var searchControl = new GSearchControl();

	// Add in a full set of searchers
	var searcher = new GwebSearch();
	var searcherOptions = new GsearcherOptions();
	searcherOptions.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	searchControl.addSearcher(searcher, searcherOptions);

	// Tell the searcher to draw itself and tell it where to attach
	var drawOptions = new GdrawOptions();
	var container = document.getElementById("google_ajax_search_container");
	var searchInput = document.getElementById("google_ajax_search_input");
	drawOptions.setSearchFormRoot(container);
	drawOptions.setInput(searchInput);
	var searchElement = document.getElementById("google_ajax_search_control");
	searchControl.draw(searchElement, drawOptions);

	// Execute an initial search
	//searchControl.execute("Google");
});

google.load("feeds", "1");

function AjaxFeed(itemCount, properties)
{
	this.itemCount = itemCount;
	this.feeds = properties;;
	
	this.doCreate = function(itemCount, feeds)	
	{	
		var feedControl = new google.feeds.FeedControl();
		feedControl.setNumEntries(itemCount);	
		//feedControl.setResultFormat(google.feeds.Feed.XML_FORMAT);
		for (label in feeds)	
		{	
			feedControl.addFeed(feeds[label], label);	
		}	
		var drawOptions =	
		{	
			drawMode : google.feeds.FeedControl.DRAW_MODE_LINEAR	
		};	
		var feedElement = document.getElementById("google_feed_control");	
		feedControl.draw(feedElement, drawOptions);	
	}

	this.onLoad = function()
	{
		this.doCreate(this.itemCount, this.feeds);
	}
}

function CreateFeedControl(itemCount)
{
	var propertiesXML;
	var url = "http://www.clanspring.com/site/clanspring/index.php?page=api&method=getRSSFeeds";
	new API().getProperties(url, function(propertiesXML)
	{
		var feed = new AjaxFeed(itemCount, propertiesXML.properties);
		feed.onLoad();
	});
}
