var health_widgets = {};

function health_loadModule(moduleUrl, targetDiv, failoverImage) {
  var health_callback = {
    onSuccess: function(o) {
    },
    onFailure: function(o) {
      document.getElementById(targetDiv).style.display = "none"; //"Module could not be loaded: Failure";
    },
    onTimeout: function(o) {
      document.getElementById(targetDiv).style.display = "none"; //"Module could not be loaded";
    },
    data: {'targetDiv': targetDiv},
    timeout: 15000
  };

  if (failoverImage !== null) {
    health_callback.onFailure = function() {document.getElementById(targetDiv).innerHTML = '<img src="' + failoverImage + '"/>'};
    health_callback.onTimeout = health_callback.onFailure;
  }

  var slug = moduleUrl.substring(moduleUrl.lastIndexOf('/') + 1);

  health_widgets[slug] = {
    'health_callback': health_callback,
    'targetDiv': targetDiv
  };

  var health_objTransaction = YAHOO.util.Get.script(moduleUrl, health_callback);
}

function health_results(success, slug, content) {
  var widget = health_widgets[slug];

  if (success) {
    document.getElementById(widget['targetDiv']).innerHTML = content;
  } else {
    widget['health_callback'].onFailure.call();
  }
}
