$(function() {
  if (window.location.pathname.indexOf("/page/outreach/view/") != -1 || window.location.hostname == "localhost") {
  	if (window.location.hostname == "localhost") {
    	var handle = "fish";
  	} else {
    	var handle = window.location.pathname.split("/").pop();
  	}
  	var url = "http://worldofopportunity.ca/contributors.php?q=" + handle + "&jsoncallback=?";
	
  	$.getJSON(url, function(data) {
  	  if (data.items.length) {
  	    var lang = $("body").attr("id");
  	    if (lang == "fr") {
  	      var imageFile = "merci.png";
  	      var anon = "Anonyme";
  	      var updated = "Cette liste est mise &agrave; jour toutes les 24 heures."
	      } else {
  	      var imageFile = "thankyou.png";
  	      var anon = "Anonymous";
  	      var updated = "This list is updated every 24 hours."
	      }
  	    
      	$("#outreachright").append("<br /><img id='thankyou' src='http://worldofopportunity.ca/img/" + imageFile + "' width='237' height='49' alt='Thank you for your support' /><table id='donorlist'><tr><th>Name</th><th>Amount</th></tr></table><p id='updated'>" + updated + "</p>");
  	  }
  	  var fullname;
  	  $.each(data.items, function(i, item) {
  	      fullname = (item[0] === "-") ? anon : item[0];
          $("#donorlist").append("<tr><td>" + fullname + "</td><td class='amount'>$" + item[1] + "</td></tr>");
      });
  	});

  }
});