// File: whathappened.js

// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the homepage.xml file
	$.get("content/whathappened.xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = '';
	  	
		// Run the function for each student tag in the XML file
		$('news',xml).each(function(i) {
			newsTitle = $(this).find("title").text();
			newsDate = $(this).find("date").text();
			newsContent = $(this).find("content").text();
			imgName = $(this).find("image_name").text();
			newsPost = $(this).find("title").attr("post"); 


			// Build row HTML data and store in string
			mydata = BuildHTML(newsTitle,newsDate,newsContent,imgName,newsPost);
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += '';
		
		// Update the DIV called Content Area with the HTML string
		$("#ContentArea").append(myHTMLOutput);
	});
});
 
 
 
 function BuildHTML(newsTitle,newsDate, studentAge,studentPhone,studentSE){
	
	// Check to see if their is a "post" attribute in the name field
	if ((newsPost) != undefined){
		newsPostHTML = "<strong>(" + newsPost + ")</strong>";
	}
	else
	{
		newsPostHTML = "";
	}

	
	if (imgName == '') {
			image_src = '';
	} else {
			image_src = '<br /><img src="images/' + imgName + '" vspace="10" border="0" alt="Eminence Road Farm Winery" />';
	}

	// Build HTML string and return
	output = '';
	output += '<div class="newsDate">' + newsDate + '</div>';
	output += '<div class="newsTitle">' + newsTitle + newsPostHTML + '</div>';
	output += newsContent;
	output += image_src;
	output += '<br /><br /><br />';
	return output;
}
