// A JavaScript for pages with picture galleries.  Last updated 20080624

// function for use with picture gallery
//  adapted from a script written by Christian Heilmann 
//   see   http://icant.co.uk/articles/dyngallery/

window.onload=function()
{
	if(document.getElementById && document.createTextNode)
	{
		document.getElementById('pixA').onmouseover=function()
		{
			dyngalleryA();	
		}																
		document.getElementById('pixB').onmouseover=function()	// added for second set
		{
			dyngalleryB();	
		}																
	}
}


function dyngalleryA()         // set variables and exit if no  pixA id
{
	var picId='bigDynPic';
	var loadingId='loadingmessage';
	var d=document.getElementById('pixA');		
		
		
// 	if(!document.getElementById(loadingId))		// if no loading message, create it and hide it
// 	{
// 		var lo=document.createElement('div');
// 		lo.appendChild(document.createTextNode('Loading...'));
// 		d.parentNode.insertBefore(lo,d);
// 		lo.id=loadingId;
// 		lo.style.display='none';				// initially hides display of "loading..."				
// 	}
	
	
	var piclinks=d.getElementsByTagName('a');
	for(var i=0;i<piclinks.length;i++)
	{
		piclinks[i].onclick=function()					// ON CLICK
		{
// 			document.getElementById(loadingId).style.display='block';    // show "loading..."
			var oldp=document.getElementById(picId);	// see if there's a big pic already
			if(oldp)
			{
			 oldp.parentNode.removeChild(oldp);			//    and remove it
			}



			var nc=document.createElement('div');		// make the new container
			d.parentNode.insertBefore(nc,d);
// 			nc.style.display='none';
			nc.id=picId;
			var newpic=document.createElement('img');	// put the picture in it
			newpic.src=this.href;						// the href of the clicked object
			newpic.alt=this.getElementsByTagName('img')[0].alt;
//			newpic.title='Click to return';
			newpic.style.border="1px solid #663300";
			newpic.style.cursor="pointer";

// 			newpic.onload=function()					// define the onload action
// 			{
// 				document.getElementById(loadingId).style.display='none'; // removes "loading.."
// 			}

			newpic.onclick=function()					// define the onclick action
			{
			 this.parentNode.parentNode.removeChild(this.parentNode);
			}
			nc.appendChild(newpic);

//     Next bit would add description from image's "alt" text, in a created paragraph
// 			np=document.createElement('p');
// 			np.appendChild(document.createTextNode(this.getElementsByTagName('img')[0].alt))
// 			nc.appendChild(np);
// 			nc.style.display='block';

			return false;	// prevent html following link (but will if js fails)
		}
	}

}



function dyngalleryB()		//  set variables and exit if no  pixB id
{
	var picId='bigDynPic';
	var loadingId='loadingmessage';
	var d=document.getElementById('pixB');		
		
		
// 	if(!document.getElementById(loadingId))
// 	{
// 		var lo=document.createElement('div');
// 		lo.appendChild(document.createTextNode('Loading...'));
// 		d.parentNode.insertBefore(lo,d);
// 		lo.id=loadingId;
// 		lo.style.display='none';			
// 	}
	
	
	var piclinks=d.getElementsByTagName('a');
	for(var i=0;i<piclinks.length;i++)
	{
		piclinks[i].onclick=function()
		{
// 			document.getElementById(loadingId).style.display='block';
			var oldp=document.getElementById(picId);
			if(oldp)
			{
			 oldp.parentNode.removeChild(oldp);
			}



			var nc=document.createElement('div');
			d.parentNode.insertBefore(nc,d);
// 			nc.style.display='none';
			nc.id=picId;
			var newpic=document.createElement('img');
			newpic.src=this.href;
			newpic.alt=this.getElementsByTagName('img')[0].alt;
//			newpic.title='Click to return';
			newpic.style.border="1px solid #663300";
			newpic.style.cursor="pointer";

// 			newpic.onload=function()
// 			{
// 				document.getElementById(loadingId).style.display='none';
// 			}
			newpic.onclick=function()
			{
			 this.parentNode.parentNode.removeChild(this.parentNode);
			}
			nc.appendChild(newpic);

			return false;
		}
	}

}


// end picture gallery
