// Load the Visualization API and the piechart package.
google.load('visualization', '1');

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(getDonationSum);

function getDonationSum() {
  var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=0At0uPwnVKCXWdHZPMXc1U2c1MlZob0ZFY1BLTDRJenc');

  query.setQuery('select sum(B)');
  query.send(function(response) {
    var data = response.getDataTable(),
        cashMoney = data.getValue(0,0).toFixed(2),
        i = cashMoney.indexOf('.');

    do {
      i -= 3;
      cashMoney = cashMoney.substring(0, i) + ',' + cashMoney.substring(i);
    } while (i > 3);
    $('#donated .amount').text(cashMoney.toString());
    $('#donated').fadeIn();
  });
}

