var timeout; //use as a handle on the timeout loop
var imageIndex = 0 // use as a counter 

function nextPhoto(containerID) {
  if (!document.getElementById) return; //protect older browsers
  var container = document.getElementById(containerID);
  var oldpic = container.getElementsByTagName('img')[0]; //asumption: only first image will be rotated
  container.style.backgroundColor = 'transparent';
  container.style.backgroundImage = 'url(' + oldpic.src + ')';
  oldpic.style.visibility = 'hidden';
  oldpic.setAttribute("src",imageNames[imageIndex]);
  timeout = window.setTimeout("reveal('photo','0')", 2500);
}

function reveal(targetID,opacity) {
  if (!document.getElementById) return; //protect older browsers
  if (opacity <= 100 ) {
    var fadeThis = document.getElementById(targetID);
    if (fadeThis.style.MozOpacity!=null) {
       fadeThis.style.MozOpacity = (opacity/100) - 0.001; //patrick h. lauke (http://www.splintered.co.uk/) workaround for Mozilla 'flash' bug - I _never_ would have caught that
    } else if (fadeThis.style.opacity!=null) {
       fadeThis.style.opacity = (opacity/100) - 0.001;
    } else if (fadeThis.style.filter!=null) {
       fadeThis.style.filter = "alpha(opacity=" + opacity + ")";
	} else if (fadeThis.style.KhtmlOpacity!=null) {
       fadeThis.style.KhtmlOpacity = opacity/100;
	}
    opacity += 5;
	fadeThis.style.visibility = 'visible';
    timeout = window.setTimeout("reveal('"+targetID+"',"+opacity+")", 100);
  } else if (imageIndex < (imageNames.length -1)) {
    imageIndex+=1;
	nextPhoto('photo_holder');
  } else {  // Jonathan Poh modification to make it loop through images infinitely
    imageIndex=0;
	nextPhoto('photo_holder');
  }  // end Jonathan Poh's modification
  
}

function loadPhoto() {
	nextPhoto('photo_holder');
}

function hidePhoto() {
	if (!document.getElementById) return; //protect older browsers
	document.getElementById('photo').style.visibility = 'hidden';
}

// a derivation (or mangling) of a script from Scott Andrew (www.scottandrew.com)
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
    obj.addEventListener(evType, fn, true); 
    return true; 
 } else if (obj.attachEvent){ 
    var r = obj.attachEvent("on"+evType, fn); 
    return r; 
 } else { 
    return false; 
 } 
}