$(document).ready(function(){ 
	$.get("http://www.pokerstars.pt/data/leader-board/all_matches.xml",{},function(xml){
	myHTMLOutput = '';
	$('match',xml).each(function(i) {
		var theMonth = $(this).find('month').text();
		  if (theMonth < 10) {
			 theLocalMonth = '0' + theMonth;
		  } else {
			  theLocalMonth = theMonth;
		  }
		var theDay = $(this).find('day').text();
		  if (theDay < 10) {
			 theLocalDay = '0' + theDay;
		  } else {
			  theLocalDay = theDay;
		  }
		var theYear = $(this).find('year').text();
		var theDate = theLocalDay + '/' + theLocalMonth + '/' + theYear;
		
		var thePro = $(this).find('pro').text();
		//Bits needed in the Results row
		var theResultValue = $(this).find('result').text();
			if (theResultValue == 1) {
				var theResult = "derrotou";
			} else {
				var theResult="perdeu para";
			}		
		var theUser = $(this).find('user').text();
		var thePrizeValue = $(this).find('prize').text();
		var thePrize = '$' + thePrizeValue + '.000';
		//to add the dark color to the updated row
		var theClass = $(this).attr('updated');
		
		mydata = buildMatchesHTML(theDate,thePro,theResult,theUser,thePrize,theClass);
			myHTMLOutput = myHTMLOutput + mydata;
		});	
		$("#writeMatches").prepend(myHTMLOutput);
	});
});
function buildMatchesHTML(theDate,thePro,theResult,theUser,thePrize,theClass){
	if (theClass == "yes") {
		theClassHTML = " class='last'";
	} 
	else
	{
		theClassHTML = "";
	}
	
	output = '';
	output += '<tr' + theClassHTML + '>';
	output += '<td>'+ theDate + '</td>';
	output += '<td>'+ thePro +'</td>';
	output += '<td>'+ theResult +'</td>';
	output += '<td>'+ theUser +'</td>';
	output += '<td class="money">'+ thePrize +'</td>';
	output += '</tr>';
	return output;
}