var currentGalleryLink = new Array();

function LoadPicture (pictureName, imageFile, captionID, captionText)
{
	document.getElementById (pictureName).src = imageFile;
	document.getElementById (captionID).innerHTML = captionText;
	
	for ( i = 0; i <document.links.length; i ++)
	{
	   	var l = document.links [i];
	   	var n = l.getAttributeNode ('onclick');
		
		if (n)
		{
			var onclick = n.value;
			
	   		if ((onclick) && (onclick.indexOf (pictureName) > 0) && (onclick.indexOf (imageFile) > 0))
	   		{
			    currentGalleryLink [pictureName] = i;
			    break;
			}
		}
	}
}
function LoadPrev (pictureName)
{
	var current = currentGalleryLink [pictureName];
	
	if (current == null)
	{
		current = document.links.length + 1;
	}
	
	var alt = null;
	
	for ( i = document.links.length - 1; i >= 0; i --)
	{
		var link=document.links [i];
		var node = link.getAttributeNode ('onclick');
		
		if (node)
		{
			var onclick = node.nodeValue;
			
			if ((onclick) && (onclick.indexOf ('LoadPicture') >= 0) && (onclick.indexOf (pictureName) > 0))
			{
				if (i < current)
				{
					eval (onclick);
					return;
				}
				
				else if (alt == null)
					alt = onclick;
			}
		}
	}
	
	if (alt)
	{
		eval(alt);
	}
}

function LoadNext(pictureName)
{
	var current = currentGalleryLink [pictureName];
	
	if (current == null)
	{
		currentGalleryLink [pictureName] = -1;
		LoadNext (pictureName);
		current = currentGalleryLink [pictureName];
	}
	
	var alt = null;
	
	for (i = 0; i < document.links.length; i ++)
	{
		var link = document.links [i];
		var node = link.getAttributeNode ('onclick');
		
		if (node)
		{
			var onclick = node.value;
			if ((onclick) && (onclick.indexOf ('LoadPicture') >= 0) && (onclick.indexOf (pictureName) > 0))
			{
				if (i > current)
				{
					eval (onclick);
					return;
				}
				
				else if (alt == null)
				{
					alt = onclick;
				}
			}
		}
	}
	
	if (alt)
	{
		eval (alt);
	}
}