var top10Terms = ['turnover', 'number of employees', 'profit', 'total wages', 'total pensions', 'total directors pay', 'highest paid director'];

var top10TermCounter = -1;

var coCallback = {
	getTop10: function(result) {
		$('#top10Term').html('Top 10 companies by '+top10Terms[top10TermCounter]);
		for (var i=0; i<10; i++) {
			$("#top10CompanyName_"+(i+1)).html(result[i]["name"]);
			$("#top10CompanyName_"+(i+1)).href = 'company.php?id='+result[i]["number"];
			if (top10Terms[top10TermCounter] != 'number of employees') {
				value = '&pound;'+result[i]["term"];
			} else {
				value = result[i]["term"];
			}
			$("#top10CompanyValue_"+(i+1)).html(value);
		}
	}
}

var remoteCO = new Company(coCallback);

function do_getTop10(initialTerm) {
	if (top10TermCounter == -1) {
		top10TermCounter = initialTerm;
	}
	if (top10TermCounter++ > 5) {
		top10TermCounter = 0;
	}
	remoteCO.getTop10(top10Terms[top10TermCounter]);
}
