function openImageWindow(e)
{
	var object = getEventObject(e);

	// Extract file name from thumbnail path
	foundAtPosition = object.src.lastIndexOf('/');
	tnFile =  object.src.substr(foundAtPosition+1);
	foundAtPosition = tnFile.indexOf('-tn.jpg');
	g_src = tnFile.substring(0,foundAtPosition);

	// Derive size of popup from thumbnail size
	var x = object.clientWidth	// width
	var y = object.clientHeight;	// height
	if (x > y)	// Landscape
	{
		x = (x * 10) + 30;
		y = (y * 10) + 3;
	}
	if (y > x)	// Portrait
	{
		x = (x * 7) + 20;
		y = (y * 7) + 3;
	}
	
	windowFeatures = "width=" + x + ",height=" + y;
    windowFeatures = windowFeatures + ",scrollbars=yes,resizable=no,status=no,menubar=no";
	url = "ff_bigView.html";
	var newWindow = window.open(url,"",windowFeatures);

}

function establishImageForDisplay()
{
	document.getElementById('largeimg').src = "images/gallery/" + window.opener.g_src + ".jpg";
}

function closeImageWindow(e)
{
   window.close();
}

function addListeners(e)
{
	if (!document.getElementById)
    	return;
  
	if(document.getElementById('thumbnails'))		// gallery.html
	{
		tns = document.getElementById('thumbnails');
		if (tns.getElementsByTagName('img'))
		{
    		links  = tns.getElementsByTagName('img');
			for (i=0;i<links.length;i++)
	  		{
				addEvent(links[i],'click',openImageWindow,false);	// set event for clicking on thumbnail
				if(links[i].clientWidth == 100)						// set classname if landscape
					links[i].className = "landscape";
	  		}
		}
   	}
	
	if(document.getElementById('bigpiccie'))		// bigview.html
	{
		establishImageForDisplay();					// sort out which piccie to display
		
		if(document.getElementsByTagName('img'))
		{
   			var images = document.getElementsByTagName('img');
			addEvent(images[0], 'click', closeImageWindow, false);
  		}
	}
}

