var feedURL = "http://notify.automationdirect.com/newsletter/news.xml";

Event.observe(window, 'load', function() 
    {
	getRSSFeed();
    });

function getRSSFeed() 
    {
    var ajaxRequest = new Ajax.Request(feedURL, {method:'get', onSuccess: processFeed, onFailure: noFeed});
    }

function noFeed() 
    {
	$('feedcontainer').update('');
    }

function processFeed(resultObj) 
    {
	var rssFeed = resultObj.responseXML;
	var itemNodes = rssFeed.getElementsByTagName('item');
	maxItems = 5;	
	var newsHTML = ''; 
    
	// Loop through the feed items up to the maximum we specified 
	for (var x = 0; x < maxItems; x++) 
	    {
	    // Regular expression search to strip out HTML in RSS descriptions
	    tagSearch = /<(.*)>.*<\/\1>/gi
	    
		// Get the feed item title
		var tString = itemNodes[x].getElementsByTagName('title')[0].firstChild.nodeValue
		tString = tString.replace(tagSearch, ''); // Strip our HTML if title
		
		// Get the feed time link
		var lString = itemNodes[x].getElementsByTagName('link')[0].firstChild.nodeValue
		lString = lString.replace(tagSearch, ''); // Strip our HTML if title
		
		//. Create a clickable link
		lString = '<p><a href="' + lString + '" class="rssheadline">' + tString + '</a></p>';
		
		// Get the feed item description
		var dString = itemNodes[x].getElementsByTagName('description')[0].firstChild.nodeValue
		
		// Strip out all the garbage in it
		dString = dString.replace(tagSearch, '');
		dString = '<p class="rssbody">' + dString + '</p>';						

        newsHTML = newsHTML + lString + dString;        
	    }	
	document.getElementById('feedcontainer').innerHTML = newsHTML;
	//$('feedcontainer').update(newsHTML);
    }