function HashDir(imageId)
{
	var temp = Math.floor(imageId / 100) % 100;
	if (temp < 10)
		return '0' + temp;
	return temp;
}

function PreviousImage()
{
	return ChangeImage(currentindex-1);
}

function NextImage()
{
	return ChangeImage(currentindex+1);
}

function ChangeImage(arrayindex)
{
	if (!imageIDs)
		return true;

	if (arrayindex < 0 || arrayindex >= imageIDs.length)
		return false;

	currentindex = arrayindex;

	var imageobject = false;
	var previmglink = false;
	var nextimglink = false;
	var bigimagelink = false;
	var imagetext = false;

	if (document.getElementById)
	{
		imageobject = document.getElementById('mainImage');
		previmglink = document.getElementById('previmglink');
		nextimglink = document.getElementById('nextimglink');
		bigimagelink = document.getElementById('bigimagelink');
		imagetext = document.getElementById('imagetext');
	}
//	else if (document.images)
//		imageobject = document.images['mainImage'];

	if (imageobject)
	{
		// change the image
		var part1 = '/media/' + HashDir(imageIDs[arrayindex]) + '/' + imageprefixes[arrayindex] + '_' + imageIDs[arrayindex];
		var part2 = imagesuffixes[arrayindex];
		imageobject.src = part1 + part2;

		// change the previous & next links
		if (previmglink)
		{
			var previndex = arrayindex-1;
			if (previndex < 0) previndex = 0;
			previmglink.search = '?textid=' + textid + '&id=' + imageIDs[previndex];
		}
		if (nextimglink)
		{
			var nextindex = arrayindex+1;
			if (nextindex >= imageIDs.length) nextindex = arrayindex;
			nextimglink.search = '?textid=' + textid + '&id=' + imageIDs[nextindex];
		}

		// change the link to the very big image
		if (bigimagelink)
		{
			if (bigImageExist[arrayindex] == 0)
				bigimagelink.style.display = 'none';
//				bigimagelink.style.visibility = 'hidden';
			// bigimagelink.pathname = part1 + 'b' + part2; doesn't work in Opera or Safari
			bigimagelink.href = bigimagelink.protocol + '//' + bigimagelink.hostname + part1 + 'b' + part2;
			if (bigImageExist[arrayindex] == 1)
				bigimagelink.style.display = 'inline';
//				bigimagelink.style.visibility = 'visible';
		}

		// change the image text
		if (imagetext)
		{
			var temp = imageTexts[arrayindex];
			if (!temp)
				temp = '&nbsp;'; // I HATE myself for doing this, but the layout fucks up otherwise
			if (imagetext.innerHTML != undefined)
				imagetext.innerHTML = temp; // innerHTML is non-standard but fast and simple
			else if(imagetext.firstChild)
				imagetext.firstChild.nodeValue = temp; // the standard W3C DOM way to do it
		}

		return false; // stop the browser from following the link
	}

	return true; // make the browser follow the link
}