// File: readXML.js

// Start function when DOM has completely loaded 


jQuery(document).ready(function()
{
  jQuery.ajax({
    type: "GET",
    url: "/files/blog.xml",
    dataType: "xml",
    success: parseXml
  });
});

function parseXml(xml){	
		// Build an HTML string
		myHTMLOutput = '';
	  	
	  	var numberOfItems = jQuery('item',xml).length;
	  	
		// Run the function for each item tag in the XML file
		jQuery('item',xml).slice(numberOfItems-3,numberOfItems).each(function(i) {
			itemTitle = jQuery(this).find("title").text();
			itemDate = jQuery(this).find('[nodeName="dc:date"]').text();
			itemLink = jQuery(this).find("link").text();
			itemContent = jQuery(this).find('[nodeName="content:encoded"]').text().slice(0,255);
						
			// Build row HTML data and store in string
			mydata = BuildHTML(itemTitle,itemDate,itemLink,itemContent);
			myHTMLOutput = mydata + myHTMLOutput;
		});
		
		// Update the DIV called Content Area with the HTML string
		jQuery("#RssContent").append(myHTMLOutput);
		
	}
 
 
 
 function BuildHTML(itemTitle,itemDate,itemLink,itemContent){
	
	// Build HTML string and return
	output = '';
	output += '<div class="rssItemDiv">';
	output += '<div class="rssItemTitle"><h3><a href="' + itemLink + '" title="Link to rss feed item ' + itemTitle + '">'+ itemTitle + '</a></h2></div>';
	output += '<div class="rssItemDate">'+ itemDate +'</div>';
	output += '<div class="rssItemContent">' + itemContent + '... <a href="' + itemLink + '">read more ></a></div>';
	output += '</div>';
	return output;
}
	 
