// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the xml file
	$.get("http://www.pokerstars.se/poker/promotions/all-star-week/results/results.xml",{},function(xml){
      	
	// Build an HTML string
	HTMLOutput = '';
			
		// Run the function for each student tag in the XML file
		$('event',xml).each(function(i) {
			matchnumber = $(this).find("matchnumber").text();
			date = $(this).find("date").text();
			time = $(this).find("time").text();
			game = $(this).find("game").text();
			teampro = $(this).find("teampro").text();
			challenger = $(this).find("challenger").text();
			winner = $(this).find("winner").text();
			
			// Build row HTML data and store in string
			mydata = buildHTML(matchnumber,date,time,game,teampro,challenger,winner);
			HTMLOutput = HTMLOutput + mydata;
		});
		
		// Update the DIV called Content Area with the HTML string
		$("#writeRoot").append(HTMLOutput);
		//$("tr:odd", "#writeRoot").addClass('rowTint');
});
	
});
 
 function buildHTML(matchnumber,date,time,game,teampro,challenger,winner){
	
	// Build HTML string and return
	output = '';
	output += '<tr>';
	output += '<td>'+ matchnumber + '</td>';
	output += '<td>'+ date +'</td>';
	output += '<td>'+ time +'</td>';
	output += '<td>'+ game +'</td>';
	output += '<td>'+ teampro +'</td>';
	output += '<td>'+ challenger +'</td>';
	output += '<td>'+ winner +'</td>';
	output += '</tr>';
	return output;
}
