function show_photo(td)
{
	// look up <td>
	while(td)
	{
		if(td.tagName.toLowerCase() == 'td') break;
		
		td = td.parentNode;
	}
	
	// not found? then exit
	if(!td) return;

	// look up popup
	var popup = document.getElementById('popup_fotomodule');
	if(!popup) return alert('Fout: kan popup niet vinden.');
	
	var arrow_left = document.getElementById('popup_arrow_left');
	var arrow_right = document.getElementById('popup_arrow_right');
	if(!arrow_left || !arrow_right) return;
	
	var thumb_fotomodule = document.getElementById('thumb_fotomodule');
	if(!thumb_fotomodule) return;
	
	var photo = null;
	var photos = td.getElementsByTagName('img');
	
	// look up (first) class thumb_fotogallery
	for(var i = 0; i < photos.length; i++)
	{
		if(photos[i].className == 'thumb_fotogallery')
		{
			photo = photos[i];
			break;
		}
	}
	
	if(!photo) return;
	
	var previousTD = null;
	var nextTD = null;
	
	var cells = td.parentNode.parentNode.getElementsByTagName('td');
	
	for(var i = 0; i < cells.length; i++)
	{
		if(cells[i].parentNode.rowIndex == td.parentNode.rowIndex && cells[i].cellIndex == td.cellIndex)
		{
			if(i == 0)
			{
				nextTD = cells[i+1];
			}
			else if(i == cells.length - 1)
			{
				previousTD = cells[i-1];
			}
			else
			{
				previousTD = cells[i-1];
				nextTD = cells[i+1];
			}
		}
	}
	
	arrow_left.style.display = previousTD ? '' : 'none';
	arrow_right.style.display = nextTD ? '' : 'none';
	
	arrow_left.onclick = function ()
	{
		show_photo(previousTD);
	}
	
	arrow_right.onclick = function ()
	{
		show_photo(nextTD);
	}
	
	var photo_src = photo.src.replace(/thumbs_\d+\/tn\d+_/, '');
	
	popup.style.display = 'block';
	
	thumb_fotomodule.src = photo_src;
	if(photo.offsetWidth < photo.offsetHeight)
	{
		thumb_fotomodule.width = (photo.offsetWidth * 400) / photo.offsetHeight;
		thumb_fotomodule.height = 400;
	} else {
		thumb_fotomodule.width = 600;
		thumb_fotomodule.height = (photo.offsetHeight * 600) / photo.offsetWidth;
	}
		
	return false;
}

function hide_photo()
{
	// look up popup
	var popup = document.getElementById('popup_fotomodule');
	if(!popup) return alert('Fout: kan popup niet vinden.');
	
	popup.style.display = 'none';
	
	return false;
}

