

function galleryImgId(galleryid, popupfunction)
{
	// no container found so don't bother
	if (typeof document.getElementById == 'undefined') { return; }
	
	// Look for the container to the gallery images
	// it should have an id specified by gallerid 
	
	var tree = document.getElementById(galleryid);
	if (tree)
	{
		// get the images within the container
		var items = tree.getElementsByTagName('img');
		
		// for each image allocate an id 
		// based on the container id plus sequence number
		for (var i = 0; i < items.length; i++)
		{
			items[i].id = "gallery_" + i;
			$imgsrc = items[i].src;
			$imgalt = items[i].alt;
			$imgeonclick = popupfunction +'("'+ $imgsrc + '","' + $imgalt + '"); return false;';
			items[i].onclick = new Function ($imgeonclick);
			items[i].style.cursor = 'pointer';
			items[i].title = $imgalt;
		}
	// all images in the container should now have a unique id
	// and and onclick call
	// and a title = alt text

	}
}

function attachEventListener(target, eventType, functionRef, capture)
{
	if (typeof target.addEventListener != 'undefined')
	{
		target.addEventListener(eventType, functionRef, capture);
	}
	else if (typeof target.attachEvent != 'undefined')
	{
		target.attachEvent('on' + eventType, functionRef);
	}
	else
	{
		eventType = 'on' + eventType;

		if (typeof target[eventType] == 'function')
		{
			var oldListener = target[eventType];

			target[eventType] = function()
			{
				oldListener();

				return functionRef();
			}
		}
		else
		{
			target[eventType] = functionRef;
		}
	}
	
	return true;
}

function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')
	{
		window.addEventListener('load', fn, false);
	}
	else if (typeof document.addEventListener != 'undefined')
	{
		document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', fn);
	}
	else
	{
		var oldfn = window.onload;
		if (typeof window.onload != 'function')
		{
			window.onload = fn;
		}
		else
		{
			window.onload = function()
			{
				oldfn();
				fn();
			};
		}
	}
}

function imgSwap(href,alt) {
	//alert(alt);
 	mainImg = document.getElementById('galleryimg');
	mainImg.src = href;
	if(mainImg.width > maxWidth){mainImg.width = maxWidth;}
	//alert(mainImg.width);
	mainImg.alt = alt;
	mainImg.title = alt;
	mainImgTxt = document.getElementById('gallerytxt');
	//alert(mainImgTxt.childNodes[0].nodeValue)
	mainImgTxt.childNodes[0].nodeValue = alt;
	
}


var maxWidth = 500;

addLoadListener(function() { galleryImgId('photothumbs','imgSwap'); });

