// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the xml file
	$.get("http://www.pokerstars.net/league-data/bpl.xml",{},function(xml){
      	
	// Build an HTML string
	HTMLOutput = '';
	
	$('date',xml).each(function(i) {
			
		HTMLOutput += '<p>Alle  toernooien van ';
		HTMLOutput += $(this).find("from_day").text() + '.';
		HTMLOutput += $(this).find("month").text() + '.2011 tot en met ';
		HTMLOutput += $(this).find("to_day").text() + '.';
		HTMLOutput += $(this).find("month").text() + '.2011 zijn in de klassementen  verwerkt.</p>';
		HTMLOutput += '<h2>De klassementen worden regelmatig bijgewerkt.</h2>';
		HTMLOutput += '<h2>Silver League</h2>';
	 	HTMLOutput += '<table class="redtable" width="90%"><tr><th>Plaats</th><th>Naam</th><th>Punten</th></tr>';
	  	
		// Run the function for each tag in the XML file
		$('ranking',xml).each(function(i) {
			place = $(this).find("place").text();
			silvername = $(this).find("silvername").text(); 
			silverpoints = $(this).find("silverpoints").text();
			
			// Build row HTML data and store in string for division 3
			mydata = buildHTML(place,silvername,silverpoints);
			HTMLOutput = HTMLOutput + mydata;
		});
		HTMLOutput += '</table>';
		
		// Update the DIV called Content Area with the HTML string
		$("#writeRoot").append(HTMLOutput);
		$("tr:odd", "#writeRoot").addClass('rowTint');
	});
});
	
});
 
 function buildHTML(place,silvername,silverpoints){
	
	// Build HTML string and return
	output = '';
	output += '<tr>';
	output += '<td>'+ place + '</td>';
	output += '<td>'+ silvername +'</td>';
	output += '<td>'+ silverpoints +'</td>';
	output += '</tr>';
	return output;
}
	 
