var ConstituentParts;
if (!ConstituentParts) { 
  ConstituentParts = {};
}
if (!ConstituentParts.Projects) { 
  ConstituentParts.Projects = {};
}
ConstituentParts.Projects = {
  'projects': [],
  'current_project_index': null,
  'interval_id': null,
  'next': null,
  
  'next_generator': function(canvas) {
    return function() {
      var pr = ConstituentParts.Projects;
      if (pr.current_project_index != null) { // First run through
        canvas.remove_focus_from(pr.projects[pr.current_project_index]);
        pr.current_project_index += 1
      }
      if (pr.current_project_index == pr.projects.length) { // End of the loop
        pr.current_project_index = 0;
      }
      canvas.switch_focus_to(pr.current_project_index);
      if (pr.current_project_index == null) { // Set up for looping on the first invocation after load
        pr.current_project_index = 0;
      }
    }
  },
  
  'setup': function(selector, canvas) {
    var pr = ConstituentParts.Projects;
    pr.projects = $(selector);
    pr.next = pr.next_generator(canvas)
    pr.interval_id = setInterval(pr.next, 5000);
    pr.next();
  }
}
