var globalCount =  0; //Math.floor(Math.random()*1);

var album = { 
  startup: function() { 
    new PeriodicalExecuter(album.cycle, 5) // change image every 5 seconds 
  }, 
  cycle: function() { 
    globalCount++;
    if (globalCount > 3) {
        globalCount = 0;
    }

    new Effect.Fade('hpImage', { // the id of the <DIV> containing the photos 
      duration: 1, 
      fps: 50, 
      afterFinish: function() { 
        new Ajax.Updater('hpImage','http://www.farmingtonsportsandrehab.com/ssi/hpImageCycle.php?id=' + globalCount, { // URL for next <IMG> tag 
          asynchronous: true, 
          onSuccess: function() { 
            new Effect.Appear('hpImage', {
              duration: 1,
              fps: 50,
              queue:'end'
            })
          } 
        }) 
      } 
    }) 
  } 
} 

window.onload = album.startup