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();
      };
    }
  }
}


// length of slideshow timer (seconds)
var timer = 5;
var bigtimer = 20;

// array of photo names
var photos = [
	['index_iceclimber', 'ExplorAider Ice-Climbing Adventures'],
	['index_cat', 'ExplorAider Sea Safari Adventures'],
	['index_climbing', 'ExplorAider Climbing Adventures'],
	['index_skiing', 'ExplorAider Mountain Snow & Rock Adventures'],
	['index_kayak', 'ExplorAider South African Wilderness Adventures'],
	['index_chalet', 'ExplorAider Mountain Chalet']
];

var hidden = "", img, count = 1, ImgTimeoutID, DivTimeoutID;

function startSlideshow()
{
	img = document.getElementById('photo');
	ImgTimeoutID = window.setTimeout('cueNextSlide()', timer * 1000);
}

function hide()
{
	hidden.className = "hidden";
	img = document.getElementById('photo');
	img.className = "index";	
}

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];
		
		if (++count == photos.length) { count = 0; }
		
		ImgTimeoutID = window.setTimeout('cueNextSlide()', timer * 1000);
	};
	
	next.src = 'images/' + photos[count][0] + '.jpg';
}

function swapimg(divid)
{
	window.clearTimeout(DivTimeoutID)
	img = document.getElementById('photo');
	img.className = "hidden";
	hidden.className = "hidden";	
	hidden = document.getElementById(divid);
	hidden.className = "inner";
	
	DivTimeoutID = window.setTimeout('hide()', bigtimer * 1000); 
};

addLoadListener(startSlideshow);