// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the xml file
	$.get("http://www.pokerstars.fr/league-data/fpl.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() + '.2010 et le ';
		//HTMLOutput += $(this).find("to_day").text() + '.';
		//HTMLOutput += $(this).find("month").text() + '.2010.</p>';
		//HTMLOutput += '<h2>Le classement sera actualis&eacute; prochainement.</h2>';

	 	HTMLOutput += '<table class="basic" width="90%"><tr> <th>Place</th><th>Division 2</th><th>Points</th></tr>';
	  	
		// Run the function for each tag in the XML file
		$('ranking',xml).each(function(i) {
			place = $(this).find("place").text();
			div2name = $(this).find("div2name").text(); 
			div2points = $(this).find("div2points").text();
			
			// Build row HTML data and store in string
			mydata = buildHTML(place,div2name,div2points);
			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,div2name,div2points){
	
	// Build HTML string and return
	output = '';
	output += '<tr>';
	output += '<td>'+ place + '</td>';
	output += '<td>'+ div2name +'</td>';
	output += '<td>'+ div2points +'</td>';
	output += '</tr>';
	return output;
}
	 