var keepRollingPhoto=true;
var startedRollingPhoto=false;
var currentPhoto=0;

function rollPhoto(){
	var oUl = document.getElementById('newPhotoSmall');
	var aLi = oUl.getElementsByTagName('li');
	
	if(keepRollingPhoto){

		if(startedRollingPhoto){	
			if(currentPhoto < (aLi.length-1)){
				currentPhoto++;
			} else {
				currentPhoto=0;
			}
			var aA = aLi[currentPhoto].getElementsByTagName('a');
			popPhoto(aA[0], true);
		}

		startedRollingPhoto=true;
		var t=setTimeout("rollPhoto();",5500);
	}
}

function popPhoto(oA, keepGoing) {
	var oUl = document.getElementById('newPhotoSmall');
	var oDiv = document.getElementById('newPhotoMedium');
	var aLi = oUl.getElementsByTagName('li');
	
	for(var i=0;i<aLi.length;i++){
		aLi[i].className = '';
	}
	
	var photoParentClone = oA.parentNode.cloneNode(true);
	var aImg = photoParentClone.getElementsByTagName('img');

	for(var i=0;i<aImg.length;i++){
		aImg[i].src = aImg[i].src.replace('small','medium');
	}
	
	oDiv.innerHTML = photoParentClone.innerHTML;

	// to get rid of the onlick, I had to get the anchor after it had been moved. Not sure why.
	var aImg2 = oDiv.getElementsByTagName('a');
	for(var i=0;i<aImg2.length;i++){
		aImg2[i].onclick = '';
	}

	oA.parentNode.className = 'current';
	
	if(!keepGoing){
		keepRollingPhoto=false;
	}
}

addLoadEvent(function(){
	rollPhoto();
});

