var timer = 5;

var photos = [
    ['mmb_1615', 'John checking the food.'],
    ['mmb_1614', 'Bud baking the spuds...'],
    ['mmb_1611', 'An empty room waiting to be used.'],
    ['mmb_1617', 'Greeting every man.'],
    ['mmb_1619', 'John jawing.'],
    ['mmb_1618', 'John is still jawing.'],
    ['mmb_1628', 'Now its Justins turn to jaw.'],
    ['mmb_1620', 'Grabbing the grub.'],
    ['mmb_1625', 'Eating and listening.'],
    ['mmb_1627', 'Dwayne drilling us.'],
    ['mmb_1626', '...Even while we are eating...']
];

var img, count = 1;

function startSlideshow()
{
  img = document.getElementById('breakfastpageimage');
  window.setTimeout('cueNextSlide()', timer * 1000);
}

function cueNextSlide()
{
  var next = new Image;

  next.onerror = function()
  {
    alert('Failed to load next image');
  };

  next.onload = function()
  {
    img.src = next.src;
    img.alt = photos[count][1];

    img.width = next.width;
    img.height = next.height;

    if (++count == photos.length) { count = 0; }

    window.setTimeout('cueNextSlide()', timer * 1000);
  };

  next.src = 'images/mmb/' + photos[count][0] + '.jpg';
}

addLoadListener(startSlideshow);

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}
