/* Config Variables */
var currPage = 1;
var nextPage = 0;
var prevPage = 0;
var maxPage = 12;

/* Links for Photos */
var PageLinks = new Array();
PageLinks[1] = '/who/about.php';
PageLinks[2] = '/services/';
PageLinks[3] = '/who/testimonials.php';
PageLinks[4] = '/trailmaps/maps.php';
PageLinks[5] = '/who/about.php';
PageLinks[6] = '/services/';
PageLinks[7] = '/who/testimonials.php';
PageLinks[8] = '/trailmaps/maps.php';
PageLinks[9] = '/who/about.php';

/* Cycle to the given "page" (photo & copy) */
function TurnPage(skipTo)
{
	/* Only run if they aren't viewing the given page */
	if (skipTo != currPage)
	{
		/* Check to make sure we have a page number to use (in case this needs to rotate automatically) */
		if (skipTo == 0)
		{
			/* Find out what the next page will be */
			nextPage = currPage + 1;
			
			/* Track what the last page was */
			prevPage = currPage;
			
			/* Set it back to 1 if the next page is over our total pages */
			if (nextPage > maxPage)
			{
				nextPage = 1;
			}
		} else {
			/* Stop our timed rotation */
			clearInterval(pageTurner);
			
			/* Set next page to what was given as an argument */
			nextPage = skipTo;
			
			/* Save the last page */
			prevPage = currPage;
		}
		
		/* Mark the next page as our current page */
		currPage = nextPage;
		
		/* Call our fade out function */
		FadeOut(prevPage, currPage);
	}
}

function FadeOut()
{
	/* Make the controls vanish */
	/*ControlFader();*/
	
	/* Turn "off" the last viewed page's number */
	/*setTimeout("TogglePageHighlight();", 500);	*/
	
	/* Make the last viewed page's photo disappear */
	Effect.toggle('Photo_' + prevPage, 'appear', { duration: 0.5});
	
	/* Make the last viewed page's copy disappear */
	/*Effect.toggle('Copy' + prevPage, 'appear', { duration: 1.0});*/

	/* Call our fade in function */
	FadeIn();
}

function FadeIn()
{
	/* Make our current page's photo appear */
	Effect.toggle('Photo_' + currPage, 'appear', { duration: 1.0});
	
	/* Make our current page's copy appear */
	/*Effect.toggle('Copy' + currPage, 'appear', { duration: 1.0});*/
	
	/* Fade our controls back in */
	/*setTimeout("ControlFader();", 1000);*/
}

function ControlFader()
{
	/* Change the link button to the current page's link URL */
	/*SetLinkURL();*/
	
	/* Make the page numbers reappear */
	Effect.toggle('PhotoControl', 'appear', { duration: 1.0});
	
	/* Make the link arrow box reappear */
	Effect.toggle('PhotoLink', 'appear', { duration: 0.5});
}

function TogglePageHighlight()
{
	/* Turn "off" the last viewed page's number */
	swapStyle('Control' + prevPage, 'controlOff');	
	
	/* Turn "on" the current page's number */
	swapStyle('Control' + currPage, 'controlOn');
}

function SetLinkURL()
{
	/* Populate the URL for the given page */
	$('PhotoLinkURL').href = PageLinks[currPage];
}
