var imgPath = null;
var imgName = null;
var imgType = null;
var imgWidth = 0;
var imgHeight = 0;
var currentPage = 0;
var totalPages = 0;

function init()
{
	/* Get image argument */
	var searchStr = window.location.search;
	searchStr = searchStr.substring(1, searchStr.length);
	
	/* Split */
	var paramsArr = searchStr.split('&');
	
	searchStr = null;
	
	/* Split */
	var pthArr = paramsArr[0].split('=');
	var nmeArr = paramsArr[1].split('=');
	var typArr = paramsArr[2].split('=');
	var wArr = paramsArr[3].split('=');
	var hArr = paramsArr[4].split('=');
	var pArr = paramsArr[5].split('=');
	var tpArr = paramsArr[6].split('=');
	
	paramsArr = null;
	
	imgPath = pthArr[1];
	imgName = nmeArr[1];
	imgType = typArr[1];
	imgWidth = parseInt(wArr[1]);
	imgHeight = parseInt(hArr[1]);
	currentPage = parseInt(pArr[1]);
	totalPages = parseInt(tpArr[1]);
	
	pthArr = null;
	nmeArr = null;
	typArr = null;
	wArr = null;
	hArr = null;
	pArr = null;
	tpArr = null;
	
	/* Update image */
	updateImage();
	
	/* Update page number */
	updatePageNumber();
	
	/* Resize window */
	window.resizeTo((imgWidth + 100), (imgHeight + 200));
}

function pageBack()
{
	if (currentPage > 1)
	{
		--currentPage;
		
		/* Update image */
		updateImage();
		
		/* Update page number */
		updatePageNumber();
	}
	else
		window.alert('Sorry! No more pages to show.');
}

function pageNext()
{
	if (currentPage < totalPages)
	{
		++currentPage;
		
		/* Update image */
		updateImage();
	
		/* Update page number */
		updatePageNumber();
	}
	else
		window.alert('Sorry! No more pages to show.');
}

function updateImage()
{
	var errorCode = -1;
	
	/* Get images object */
	var imgObj = document.images['pageImg'];
	
	if (imgObj != null)
	{
		/* Setup image source, width, and height */
		imgObj.src = imgPath + imgName + currentPage.toString(10) + '.' + imgType;
		imgObj.width = imgWidth;
		imgObj.height = imgHeight;
		
		errorCode = 0;
	}
	
	imgObj = null;
	
	if (errorCode == -1)
		window.alert('Error! There is a problem with this page. Please contact webmaster@noelchadwick.co.uk.');
}

function updatePageNumber()
{
	var errorCode = -1;
	
	/* Get div object */
	var divObj = document.all['pageNum'];

	if (divObj != null)
	{
		/* Set page number */
		divObj.innerHTML = 'Page ' + currentPage.toString(10) + ' of ' + totalPages.toString(10);
		
		errorCode = 0;
	}

	divObj = null;
	
	if (errorCode == -1)
		window.alert('Error! There is a problem with this page. Please contact webmaster@noelchadwick.co.uk.');
}

function openPicture(picParams)
{
	var url = '1817_menu_page.html?' + picParams;
	
	/* Open page in new window */
	window.open(url, 0, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=32,height=32');
	
	url = null;
}
