/*

Code by Jeremy Keith (http://www.adactio.com/). Please visit his site to
see what a real expert can do.

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.

*/

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; 

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

	return false;
}