/*

This function checks for the existence of an element with the ID 'imagegallery'.
If this element exists, the showPic behaviour is added to any links it contains.

This function is triggered when the page loads.
The addLoadEvent.js file is required for this.

*/

addLoadEvent(imageGallery);

function imageGallery() {

	if (!document.getElementById) return false;

	if (!document.getElementById('imagegallery')) return false;

	var gallery = document.getElementById('imagegallery');

	var lnks = gallery.getElementsByTagName('a');

	for (var i=0;i<lnks.length;i++) {

		lnks[i].onclick = function() {

			return showPic(this);

		}

		lnks[i].onkeypress = lnks[i].onclick;

	}
}

/*

This function takes a link as its argument.
The 'href' value of the link is used as the 'src' value for the 'placeholder' image element.
The 'title' value of the link is used as the textNode value of the 'desc' element.
If there is no 'title' value, the link text is used instead.

*/

function showPic (whichpic) { 

	if (!document.getElementById) return true;
 
	var picture = whichpic.getAttribute('href');

	if (!document.getElementById('placeholder')) return true;

	document.getElementById('placeholder').setAttribute('src',picture);

	if (!document.getElementById('desc')) return false; 

	if (whichpic.getAttribute('title')) {

		document.getElementById('desc').childNodes[0].nodeValue = whichpic.getAttribute('title');

	} else {

		document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;

	}

	return false;
}