// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the xml file
//	$.get("/fr/poker/promotions/spl/data/SPL.xml",{},function(xml){
	$.get("http://www.pokerstars.com/league-data/SPL.xml",{},function(xml){
	// Build an HTML string
	HTMLOutput = '';
	$('date',xml).each(function(i) {
			
		HTMLOutput += '<p>Le classement prend en compte les tournois compris entre le ';
		HTMLOutput += $(this).find("from_day").text() + '.';
		HTMLOutput += $(this).find("month").text() + '.2009 et le ';
		HTMLOutput += $(this).find("to_day").text() + '.';
		HTMLOutput += $(this).find("month").text() + '.2009';
		HTMLOutput += '<h2>Le classement est actualisé chaque mardi et vendredi.</h2>';
	 	HTMLOutput += '<table class="tbl_basic_center"><tr><th>Place</th><th width="161">Division 1</th><th width="101">Points</th><th width="162">Division 2</th><th width="101">Points</th>';
	  	
		// Run the function for each student tag in the XML file
		$('ranking',xml).each(function(i) {
			place = $(this).find("place").text();
			d1Name = $(this).find("div1name").text();
			d1Points = $(this).find("div1points").text();
			d2Name = $(this).find("div2name").text();
			d2Points = $(this).find("div2points").text();
			
			// Build row HTML data and store in string
			mydata = buildHTML(place, d1Name, d1Points, d2Name, d2Points);
			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, d1Name, d1Points, d2Name, d2Points){
	
	// Build HTML string and return
	output = '';
	output += '<tr>';
	output += '<td>'+ place + '</td>';
	output += '<td>'+ d1Name +'</td>';
	output += '<td>'+ d1Points +'</td>';
	output += '<td>'+ d2Name +'</td>';
	output += '<td>'+ d2Points +'</td>';
	output += '</tr>';
	return output;
}
	 