function updateRecentPledges() {
	jQuery.ajax({
		url: "/wp-content/plugins/tp-pledge/recent.ajax.php?p=recent",
		cache: false,
		success: function(html) {
			//jQuery("#pledge-recent-list li").remove();
			jQuery("#pledge-recent-list").replaceWith(html);
		}
	});
}

function updateTotalPledges() {
	var total = jQuery("#total-pledge-counter");
	var previous = total.html();
	jQuery.ajax({
		url: "/wp-content/plugins/tp-pledge/recent.ajax.php?p=total",
		cache: false,
		success: function(data) {
			total.replaceWith(data);
			if (total.html() != previous) {
				total.fadeIn("slow");
				total.fadeOut("slow");
				total.fadeIn("slow");
			} else {
				total.show();
			}
		}
	});
}
var intervalRecent = null;
var intervalTotal = null;

jQuery(document).ready(function(){
  if (jQuery("#pledge-recent-list").length > 0) {
  
    if(intervalRecent != null) clearTimeout(intervalRecent);
  	intervalRecent = setInterval(updateRecentPledges, 120000);
  }
	if (jQuery("#total-pledge-counter").length > 0) {
	
  	if(intervalTotal != null) clearTimeout(intervalTotal);
  	intervalTotal = setInterval(updateTotalPledges, 120000);
  }
});
