var timer = 3;

var photos = [
    ['villa_clara_slide_250_05', 'Flowers on the wall'],
    ['villa_clara_slide_250_04', 'village view'],
    ['villa_clara_slide_250_03', 'geraniums galore'],
    ['villa_clara_slide_250_15', 'the villa and pool'],
    ['villa_clara_slide_250_14', 'the villa front entrance'],
    ['villa_clara_slide_250_13', 'the terrace'],
    ['villa_clara_slide_250_07', 'kitchen view'],
    ['villa_clara_slide_250_08', 'lounge'],
    ['villa_clara_slide_250_10', 'the swimming pool'],
    ['villa_clara_slide_250_11', 'a geranium wall'],
    ['villa_clara_slide_250_01', 'bedroom'],
    ['villa_clara_slide_250_12', 'terrace view'],
    ['villa_clara_slide_250_02', 'bedroom'],
    ['villa_clara_slide_250_09', 'bedroom'],
    ['villa_clara_slide_250_06', 'localchurch']
];

var img, count = 1;

function startSlideshow()
{
  img = document.getElementById('photo');
  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/slides/' + 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();
      };
    }
  }
}

