	/**
 * @author Dave Alden
 */

// Globals

dispItems = 2; // Number of News Item headlines to display from RSS feed

window.onload = function()
{
	initRSS();
}

//Initialises RSS feed by making the HTTP request
function initRSS()
{	
	// Create a request object for RSS XML
	var req = new bbcjs.http.get('/cbbc/presspack/rss/cbbc_news/club/rss.xml', 
		{onLoad:handleLoad});			
}

// Processes requested XML, which is passed back as a JSTools HTTP Request object
function handleLoad(request)
{				
	// Retreive responseXML Object
	var myXML = request.xml();
	
	// Get all the news items
	var items = myXML.getElementsByTagName("item");	
	
	// Get the div to display them in
	var dispArea = document.getElementById('rss-feed');
	
	// for each news item
	for (i=0; i<dispItems ;i++)
	{
		
		// make sure there are more items to display
		if (i<items.length)
		{
			// create a new <p>
			var np = document.createElement('p');
																	
			// create a new <a>
			var na = document.createElement('a');
			
			// get the item.title (assume only one)
			na.innerHTML = items[i].getElementsByTagName("title")[0].firstChild.nodeValue;			
			
			// set the href value to item.link
			na.href = items[i].getElementsByTagName("link")[0].firstChild.nodeValue;
			
			
			// add the new <a> as a child of <p>
			np.appendChild(na);
			
			// add the new <p> as a child of dispArea
			dispArea.appendChild(np);
						
		} // if there are more news items
		
	}// for each news item
	
	
	
} //handleLoad()
