// <![CDATA[ 

//Turn a list of photos into a list of anchor links with background images			
function ActivatePhotoList(photoList) {
	//If getElementById works 
	if (document.getElementById(photoList)) {
		var set = document.getElementById(photoList);
		
		var photoArray = new Array();
		
		for (i = 0; i < set.childNodes.length; i++) {
		
			//Remove empty text nodes from the list.
			if (set.childNodes[i].nodeType == 3) {
				set.removeChild(set.childNodes[i]);
				i--;
			}
			//Add the photo source to the photoArray
			else {
				photoArray[i] = set.childNodes[i].firstChild.getAttribute('src');
				set.childNodes[i].removeChild(set.childNodes[i].firstChild);
				
				var newLink = document.createElement('A');
				newLink.setAttribute('href', 'javascript:ExpandPhotoList(' + i + ');');
				newLink.setAttribute('id', 'link' + i);
				newLink.setAttribute('label', 'click to expand');
				newLink.style.backgroundImage = "url(" + photoArray[i] + ")";
				
				set.childNodes[i].appendChild(newLink);
				
				document.getElementById("link" + i).className = "closed";
			}
		}
		document.getElementById('link0').className = "opened";
	}
}

//Expand a selected photo and reduce the last-selected photo
function ExpandPhotoList(id) {
	var linkObj = document.getElementById('link' + id);
	var listObj = linkObj.parentNode.parentNode;
	
	for (i = 0; i < listObj.childNodes.length; i++) {
	
		var curElement = document.getElementById('link' + i);
	
		if (curElement.className == "opened") {
			curElement.className = "closed";
		}
	}
	linkObj.className = "opened";
}

// ]]>


function randomImg(n, prefix) {
	//Generate a random number from 1 to n
	var ranNum = Math.floor(Math.random() * n) + 1;
	
	//Create the random id by concatenating the prefix and the random number
	var id = prefix + ranNum;
	
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'inline';
	}
}
