// File: patient.js
//
// Depends on: utd.js
//
// Description: Objects that are used by pages in the patient site.

UTD.namespace("contributor");

/**
 * A singleton object that contains the detailed credentials of all contributors of the current 
 * topic.  The credentials are specified as HTML that can be shown when the user hovers over a 
 * contributor name.  
 */
UTD.contributor.Credentials = function() {
  var object = {};
  var _contribMap = {};

  // The id of the container to be updated with the credentials HTML.
  object.credentialsId;

  // Adds the credentials of a contributor to this object.  The input contributor object contains
  // the id of the contributor and the HTML that contains the contributor's credentials.
  object.add = function(contributor) {
    _contribMap[contributor.id] = contributor;
  }; // add
  
  // Updates the credentials container with the HTML for the contributor specified by
  // contribId and shows the credentials under the name of the contributor.
  object.showCredentials = function(contributorId) {
    var contributor = _contribMap[contributorId];
    if (contributor) {
      var credentials = document.getElementById(this.credentialsId);
      var contributorLink = document.getElementById(contributorId);
      if (credentials) {
    	  credentials.innerHTML = contributor.html;
          UTD.util.repositionElement(credentials, contributorLink, 5, 15);
          credentials.style.visibility = "visible";    	  
      }
    }
  }; // showCredentials

  // Hides the credentials container.
  object.hideCredentials = function() {
    var credentials = document.getElementById(this.credentialsId);
    if (credentials) {
      credentials.style.visibility = "hidden";
    }
  }; // hideCredentials

  return object;
}(); // UTD.contributor.Credentials
