function ToggleDivStyle(objDIVElement, blnStatus)
{
	var strStyle = 'none';
	if (blnStatus) {strStyle = 'inline';}
	objDIVElement.style.display = strStyle;
}


function TogglePagingList(intMaxPagesToDisplay, intTotalNumberOfPages, intCurrentPage, intCols, intMaxImagesPerPage, strImageFolder)
{
	// Set the paging values based on
	// intMaxPagesToDisplay: Pre-set value of the total number of pages to display on top
	// intTotalNumberOfPages: The actual total number of pages within the album
	// intCurrentPage: The current page that has been clicked, this will determine which DIV elements to display

	// if the intCurrentPage > 1 then write out 'previous' first
	// Write out the page numbers. These move depending on the clicked page number
	// if the intCurrentPage < intTotalNumberOfPages then write out 'next' as last
	// e.g. intMaxPagesToDisplay = 5, intTotalNumberOfPages = 7, intCurrentPage = 3, display: 'previous 2 3 4 5 6 next'
	// e.g. intMaxPagesToDisplay = 5, intTotalNumberOfPages = 7, intCurrentPage = 6, display: 'previous 3 4 5 6 7 next'
	// e.g. intMaxPagesToDisplay = 5, intTotalNumberOfPages = 3, intCurrentPage = 2, display: '1 2 3'

	// This script will create an array with the required amount of elements. Since this number will not change during a visit, it can be static for the duration
	// It will then calculate which page numbers must be stored inside this array, according to an Algorythm and based on the current page
	// Every page link will call this function with a new current page number. All the other arguments must remain the same since they are also used for the Ajax script

	// Set the array and populate it with the initial values
	var intMaxArrayElements = intTotalNumberOfPages;
	var arrPages = new Array(intMaxArrayElements); // boolean values
	var arrValues = new Array(intMaxArrayElements); // text values
	for (i = 0; i < intMaxArrayElements ; i++) {arrPages[i] = false; arrValues[i] = '';	ToggleDivStyle(document.getElementById(i + 1), false);}

	// Set the values for the previous link
	if ((intCurrentPage > 1))
	{
		ToggleDivStyle(document.getElementById("previous"), true);
		strLinkValue = "TogglePagingList(" + intMaxPagesToDisplay + ", " + intTotalNumberOfPages+ ", " + (intCurrentPage - 1) + ", " + intCols + ", " + intMaxImagesPerPage + ", \"" + strImageFolder + "\")";
		document.getElementById("previous").innerHTML = "<a href='#' onClick='javascript:" + strLinkValue + "'>" + document.getElementById("previous").title + "</a>&nbsp;";
	}
	else
	{
		ToggleDivStyle(document.getElementById("previous"), false);
	}
	// Set the values for the next link
	if ((intCurrentPage < intTotalNumberOfPages) && ((intTotalNumberOfPages - intCurrentPage) > 0))
	{
		ToggleDivStyle(document.getElementById("next"), true);
		strLinkValue = "TogglePagingList(" + intMaxPagesToDisplay + ", " + intTotalNumberOfPages+ ", " + (intCurrentPage + 1) + ", " + intCols + ", " + intMaxImagesPerPage + ", \"" + strImageFolder + "\")";
		document.getElementById("next").innerHTML = "<a href='#' onClick='javascript:" + strLinkValue + "'>" + document.getElementById("next").title + "</a>&nbsp;";
	}
	else
	{
		ToggleDivStyle(document.getElementById("next"), false);
	}

	// Set the values for the page numbers inside the array
	// Available number of pages is smaller than the maximum allowed, so the array always has page 1 through N and the remainder is empty
	if (intTotalNumberOfPages <= intMaxPagesToDisplay)
	{
		for (j = 0; j < intMaxPagesToDisplay; j++)
		{
			if (j <= intTotalNumberOfPages)	{arrPages[j] = true; arrValues[j] = j;}
			else {arrPages[j] = false; arrValues[j] = '';}
		}
	}
	// Otherwise calculate which page numbers to store based on the current page
	else
	{
		var intMaxPageAtPosOne = (intTotalNumberOfPages - (intMaxPagesToDisplay - 1)) + 1;
		if (intCurrentPage == 1) {var intFirstPage = 1;}
		else
		{
			if ((intCurrentPage <= intMaxPageAtPosOne) && (intCurrentPage > 1)) {var intFirstPage = intCurrentPage - 1;}
			else {var intFirstPage = intMaxPageAtPosOne - 1;}
		}
		for (k = 0; k < intMaxPagesToDisplay; k++)	{arrPages[k] = true; arrValues[k] = intFirstPage + k;}
	}
	
	// Display the page numbers
	if (intTotalNumberOfPages > 1)
	{
		for (l = 0; l < intMaxPagesToDisplay; l++)
		{
			if (arrValues[l] != '')
			{
				ToggleDivStyle(document.getElementById(arrValues[l]),arrPages[l]);
				if (intCurrentPage == arrValues[l])	{document.getElementById(arrValues[l]).innerHTML = "<b>" + arrValues[l] + "</b>&nbsp;";}
				else
				{
					strLinkValue = "TogglePagingList(" + intMaxPagesToDisplay + ", " + intTotalNumberOfPages+ ", " + arrValues[l] + ", " + intCols + ", " + intMaxImagesPerPage + ", \"" + strImageFolder + "\")";
					document.getElementById(arrValues[l]).innerHTML = "<a href='#' onClick='javascript:" + strLinkValue + "'>" + arrValues[l] + "</a>&nbsp;";
				}
			}
		}
	}

	// Display the photo's
	TogglePhotoGrid(intCurrentPage, intCols, intMaxImagesPerPage, strImageFolder);
}


function TogglePhotoGrid(intCurrentPage, intCols, intMaxImagesPerPage, strImageFolder)
{
	// Call the Ajax script to load the external file into the DIV element
	// Remember, since this external file will handle server-side code, we must pass on all the necessary arguments back to that page
	ajax_loadContent('photoContainer','/system/rxml/album.html?page=' + intCurrentPage + '&cols=' + intCols + '&images=' + intMaxImagesPerPage + '&folder=' + strImageFolder);
}