
function Project(projectId) {
    var this_ = this;
    var projectId_ = projectId;
    
    /**
     * Constructor. Note that this is called at the end of the class.
     */
    var init = function init() {
    }
    
    Project.prototype.setElement = function setElement(id, value) {
        if (id != null) {
            var element = document.getElementById(id);
            
            if (element != null) {
               element.innerHTML = value;
            }
        }
    }
    
    Project.prototype.setProjectData = function setProjectData(project) {
        if (project != null) {
            this_.setElement("funded", project.funding);
            this_.setElement("goal", project.goal);
            this_.setElement("remaining", project.remaining);
            
            var outcomeId = 0;
            for (var i = 1; i < 12; i++) {
               var id = "vo" + i;
               var voCount = document.getElementById(id);
               if (voCount == null) {
                  outcomeId = i - 1;
                  break;
               }
            }
            
            if (outcomeId > 0) {
               var value = project.remaining;
               value = value.replace(/,/, "");
               value = value.replace(/\$/, "");
               var id = "vo" + outcomeId;
               var element = document.getElementById(id);
               if (element != null) {
                  element.setAttribute("value", value);
               }
               
               this_.setElement("vo" + outcomeId + "_amount", project.remaining);
            }
        }
    }
    
    /**
     * Kicks off a refresh cycle.
     */
    Project.prototype.refresh = function refresh() {
        $.getJSON("/dy/data/project/uk.json?id=" + projectId_, null, this_.setProjectData);
    }

    init();
}


