
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) {
              // If we want to animate it...
               //var highlight = dojo.lfx.html.unhighlight(element, [255,255,160], 800);
               //var unhighlight = dojo.lfx.html.highlight(element, [255,255,255], 4000);
               //var animations = new dojo.lfx.Chain(highlight, unhighlight);
               //animations.play();
               
               element.innerHTML = value;
            }
        }
    }
    
    Project.prototype.setProjectData = function setProjectData(type, project, evt) {
        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() {
        // do the ajax request
        dojo.io.bind({
            url: "/dy/data/project/ag.json?id=" + projectId_,
            load: this_.setProjectData,
            mimetype: "text/json"
        });
    }

    init();
}

function showMore() {
    document.getElementById("lessValueOutcomes").style.display = "none";
    document.getElementById("moreValueOutcomesButton").style.display = "block";
    
    if (BrowserDetect != null && BrowserDetect.browser == "Firefox" || BrowserDetect.browser == "Explorer") {
      // IE and Firefox will support animation - Safari won't due to a bug in Dojo 0.4.3
      var wipeIn = dojo.lfx.wipeIn(document.getElementById("moreValueOutcomes"), 200, dojo.lfx.easeIn(2), null);
      wipeIn.play();
    } else {
      // fall back to not using animation
      document.getElementById("moreValueOutcomes").style.display = "block";
    }
}

function showLess() {
    document.getElementById("lessValueOutcomes").style.display = "block";
    document.getElementById("moreValueOutcomes").style.display = "none";
    document.getElementById("moreValueOutcomesButton").style.display = "none";
}