// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the xml file
//	$.get("http://www.pokerstars.com/de/poker/promotions/gpl/data/GPL.xml",{},function(xml){
	$.get("http://www.pokerstars.com/league-data/GPL.xml",{},function(xml){
      	
	// Build an HTML string
	HTMLOutput = '';
	
	$('date',xml).each(function(i) {
			
		HTMLOutput += '<p>Die Rangliste ber&uuml;cksichtigt Turniere vom ';
		HTMLOutput += $(this).find("from_day").text() + '.';
		HTMLOutput += $(this).find("month").text() + '.2009 bis zum ';
		HTMLOutput += $(this).find("to_day").text() + '.';
		HTMLOutput += $(this).find("month").text() + '.2009.</p>';
		HTMLOutput += '<h2>Ranglisten f&uuml;r die Divisionen 1 - 3:</h2>';

	 	HTMLOutput += '<table class=\"tblStyle7a\"><tr><th width=\"51\">Platz</th><th width=\"79\">Division 1</th><th width=\"56\">Punkte</th><th width=\"93\">Division  2</th><th width=\"57\">Punkte</th><th width=\"90\">Division 3</th><th width=\"64\">Punkte</th></tr>';
	  	
		// Run the function for each student tag in the XML file
		$('ranking',xml).each(function(i) {
			place = $(this).find("place").text();
			div1name = $(this).find("div1name").text();
			div1points = $(this).find("div1points").text();
			div2name = $(this).find("div2name").text();
			div2points = $(this).find("div2points").text();
			div3name = $(this).find("div3name").text(); 
			div3points = $(this).find("div3points").text();
			
			// Build row HTML data and store in string
			mydata = buildHTML(place,div1name,div1points,div2name,div2points,div3name,div3points);
			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,div1name,div1points,div2name,div2points,div3name,div3points){
	
	// Build HTML string and return
	output = '';
	output += '<tr>';
	output += '<td>'+ place + '</td>';
	output += '<td>'+ div1name +'</td>';
	output += '<td>'+ div1points +'</td>';
	output += '<td>'+ div2name +'</td>';
	output += '<td>'+ div2points +'</td>';
	output += '<td>'+ div3name +'</td>';
	output += '<td>'+ div3points +'</td>';
	output += '</tr>';
	return output;
}
	 