//Dynamic gallery
function dyngallery()
{

  if(document.getElementById && document.createTextNode)
  {

	  //Assign the name of the display image to a variable
	  var picId='PreviewPic';
	  var picText='PreviewText';
	  //Find the Thumbs Div and assign it to d
	  var d=document.getElementById('thumbs');
	  //If there is not a Thumbs Div, then exit
	  if(!d){return;}
	  //Get all elements <a href> from the Thumbs Div and assign to piclinks
	  var piclinks=d.getElementsByTagName('a');
	  //Loop through all <a> tags
	  for(var i=0;i<piclinks.length;i++)
	  {
		//Assign the onclick behavior to all <a> tags
		piclinks[i].onclick=function()
		{
	
		  var selDiv=document.getElementById('selectedDiv');
	
		  if(selDiv)
		  {
			var selImgs=selDiv.getElementsByTagName('img');
			
			for(var j=0;j<selImgs.length;j++)
			{
				selImgs[j].src='images/hint/tnUnSelected';
			}		
		  }
		  //Get the PreviewImg object into the variable oldp
		  var oldp=document.getElementById(picId);
		  var oldtxt=document.getElementById(picText);
		  var selpicid='sel'+this.id;
		  var selpic=document.getElementById(selpicid);
		  var oldtxtParent;
		  var np;
		  //If oldp exist, then find its parent and remove it
		  if(oldp)
		  {
		   if(oldtxt)
		   
			  {
				oldp.src=this.href;
				//Assign the alt value to the first image that is contained in the <a> that was clicked
				oldp.alt=this.getElementsByTagName('img')[0].alt;  
				
				oldtxtParent=oldtxt.parentNode;
				oldtxtParent.removeChild(oldtxt);
				np=document.createElement('p');
				np.id=picText
				np.appendChild(document.createTextNode(oldp.alt));
				oldtxtParent.appendChild(np);
				
			  }
		  }
		  if(selpic)
		  {
			selpic.src='"images/hint/tnSelected.jpg"';
		  }
		  
		  return false;
	   }
	}
   }
}
