function loadStats(pokemon) {

	comparerGroup.style.opacity="0.5";

	var actionUrl="comparer/comparer_ajax.php?pokemon="+pokemon;

	$.ajax({
		url: actionUrl,
		cache: true,
		dataType: "json",
		success: function(reply){
			if (reply.error==0) {
				// Blank the error message.
				comparerError.innerHTML="";
				// Set labels
				comparerTopLeft.innerHTML=reply.physicalAttackValue;
				comparerTopRight.innerHTML=reply.specialAttackValue;
				comparerMiddleLeft.innerHTML=reply.physicalAverageValue;
				comparerMiddleRight.innerHTML=reply.specialAverageValue;
				comparerBottomLeft.innerHTML=reply.physicalDefenseValue;
				comparerBottomRight.innerHTML=reply.specialDefenseValue;
				// Set widths
				comparerTopLeft.style.width=reply.physicalAttackPercent;
				comparerTopRight.style.width=reply.specialAttackPercent;
				comparerMiddleLeft.style.width=reply.physicalAveragePercent;
				comparerMiddleRight.style.width=reply.specialAveragePercent;
				comparerBottomLeft.style.width=reply.physicalDefensePercent;
				comparerBottomRight.style.width=reply.specialDefensePercent;
				// Yeah.
				comparerGroup.style.opacity="1";
			} else {
				comparerError.innerHTML=reply.errorMessage;
			}
		}
	});

}

function percentify(num) {
	// This is probably done somewhere in the built in functions, but oh well.
	return Math.floor(num*10000)/100;
}

function comparerInitialise() {
	// This has to be delayed so the divs in question are created before it runs.
	comparerError=document.getElementById('comparerError');
	comparerGroup=document.getElementById('comparerGroup');

	comparerTop=comparerGroup.getElementsByClassName("comparer")[0];
	comparerTopLeft=comparerTop.getElementsByClassName("comparerBarLeft")[0];
	comparerTopRight=comparerTop.getElementsByClassName("comparerBarRight")[0];

	comparerMiddle=comparerGroup.getElementsByClassName("comparer")[1];
	comparerMiddleLeft=comparerMiddle.getElementsByClassName("comparerBarLeft")[0];
	comparerMiddleRight=comparerMiddle.getElementsByClassName("comparerBarRight")[0];

	comparerBottom=comparerGroup.getElementsByClassName("comparer")[2];
	comparerBottomLeft=comparerBottom.getElementsByClassName("comparerBarLeft")[0];
	comparerBottomRight=comparerBottom.getElementsByClassName("comparerBarRight")[0];

	document.getElementsByTagName("button")[0].style.display="none";

	loadStats(comparerPokemon);
}

$(document).ready(function(){
	comparerInitialise();
});
