


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
			pattern = /"/g;
		for (var i = 0; i < items.length; i++)
		{
			items[i].id = "gallery_" + i;
			$imgsrc = items[i].src;
			//alert(items[i].alt);
			$imgalt = items[i].alt;
			$imgalt2 = $imgalt.replace(pattern,'&#034;');
			//alert($imgalt);
			$imgeonclick = popupfunction +'("'+ $imgsrc + '","' + $imgalt2 + '"); 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 imgPop(href,alt) {
	gallery = "gallery_pop.php?" + "img="+ href + "&alt=" + alt;
	win = window.open(gallery, "gallery", 'height=450,width=350,top=10,left=10,scrollbars=1,resizable,location');
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


addLoadListener(function() { galleryImgId('galleryimages','imgPop'); });
