/**
 * 
 */
var App = {
  /**
   * 
   */
  startShowreels : function() {
    //
    new PeriodicalExecuter(function(pe) {
      // Repeat for each showreel.
      $('showreel').select('.reel').each(function(showreel) {
        // Get current project and image.
        var currentProject = showreel.down('.current-project');
        var currentImage = currentProject.down('img.current-image');
        // Look for next image in project.
        var nextImage = currentImage.nextSiblings().first();
        
        // Is there a further image in the current project?
        // If so, show it.
        if(nextImage) {
          currentImage.fade();
          currentImage.removeClassName('current-image');
          nextImage.appear();
          nextImage.addClassName('current-image');
        } else {
          // If no further image exists in the current project,
          // look for the next project.
          var nextProject = currentProject.nextSiblings().first();
          
          // Found a further project?
          // If so, show the first image.
          if(nextProject) {
            currentImage.fade();
            currentImage.removeClassName('current-image');
            currentProject.fade();
            currentProject.removeClassName('current-project');
            nextProject.appear();
            nextProject.addClassName('current-project');
            nextImage = nextProject.down('img');
            nextImage.appear();
            nextImage.addClassName('current-image');          
          } else {
            // No further project?
            // Go back to the start then.
            var firstProject = showreel.down('.project');
            var firstImage = firstProject.down('img');
            currentImage.fade();
            currentImage.removeClassName('current-image');
            currentProject.fade();
            currentProject.removeClassName('current-project');
            firstProject.appear();
            firstProject.addClassName('current-project');
            firstImage.appear();
            firstImage.addClassName('current-image');                    
          }
        }        
      });
    }, 5);
  }
};