// File: readXML.js

// numberOfItems - variable is passed from a calling page and determins how many rss items to show on that page

// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the students.xml file
	$.get(rssAddress,{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	 	myHTMLOutput += '<div id="newsRel">';
	  	
		var myCount = 0;
		// Run the function for each item tag in the XML file
		
		$('item',xml).each(function(i) {			
			newsTitle = $(this).find("title").text();
			newsDesc = $(this).find("description").text();
			newsLink = $(this).find("link").text();
			
			// Build row HTML data and store in string
			mydata = BuildStudentHTML(newsTitle,newsDesc,newsLink);			
			myHTMLOutput = myHTMLOutput + mydata;
			if(myCount == numberOfItems) return false;
			myCount++;
		});
		
		myHTMLOutput += '</div>';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea").append(myHTMLOutput);
	});
});
 
 
 
 function BuildStudentHTML(newsTitle,newsDesc,newsLink){
	
	
	// Build HTML string and return
	output = '';
	output += '<div class="newsItem">';
	output += '<div class="newsTitle"><a href="'+ newsLink + '">' + newsTitle + '</a></div>';
	output += '<div class="newsDesc">' + newsDesc +'</div>';
	output += '</div>';
	return output;
}
	 