//************************************************************************************************* 
// Design           	: FvdM Design Studio's 2003-2010
// Initial file date	: 10 May, 2003
// Function(s)			: Next and previous photo functions
// Change history		:	Date		By		Revision	Description
//							10-05-2003	FvdM	1.0			Initial version.
//							17-09-2005	FvdM	1.1			Added function ShowSelectedPhoto, to
//															get the first photo correct when accessing
//															'Photopage.html' for the first time.
//							24-10-2006	FvdM	2.0			Changed routines:
//															 - ShowSelectedPhoto();
//															 - ShowPhoto();
//															   added 'width' / 'height' properties, corrected
//															   by the 'ScrResFactor' / 'ScaleFactor' variable.
//															   Variable 'ScaleFactor' is needed to scale the
//															   photo to the maximum allowed 'MaxPhotoHeight'.
//															   added ' window.status="" ' line to hide
//															   javascript-routine in status line.
//															New routines:
//															 - ScreenRes();
//															   function to set zoom-factor, because of
//															   different screen resolutions of website
//															   audience. In this way it is possible to get
//															   the nicest (largest) view on screen.
//															 - Screenheight function:
//															   This global function determines the used screen
//															   settings of the viewer and automatically sets
//															   the best scaling factor for viewing via the
//															   web browser.
//							13-01-2007	FvdM	2.1			New Screen resolution added: 1600x1200 pixels.
//															 - Screenheight function adapted.
//															New routines:
//															 - ResetPhoto();
//															   function to reset photo-dimensions and 
//															   calculate new dimensions, to prevent strange
//															   zooming effects during switch from vertical to
//															   horizontal and horizontal to vertical photos.
//															Changed routines:
//															 - PrevPhoto(), NextPhoto();
//															   ResetPhoto() routine added to reset photo
//															   dimensions to default.
//															   SetTimeout() function added to create a delay
//															   between the ResetPhoto() and the ShowPhoto()
//															   function. This will eliminate the strange
//															   zooming effects when switching to the previous
//															   or next photo.
//							20-01-2007	FvdM	2.2			New routines:
//															 - PreLoadPhotos();
//															   function to preload all photos used on the 
//															   photopage, to speed up the loading of the page
//															   and photos.
//															   This routine uses variable 'LastPhotoNumber'
//															   from script file 'Photoinfo.js'.
//															   Therefore it is important that this files loads
//															   first in 'Photopage.html', else the (end)-value
//															   is not clear.
//															   Variable 'PhotoBuffer' defined.
//							09-06-2007	FvdM	2.3			Changed routines:
//															 - Screenheight function adapted.
//															   The case statement with multiple values, separated
//															   by a colon, didn't work properly.
//															   Separated the case statements to single entries. 
//							12-03-2010	FvdM	2.4			Added "document.CurrentPhoto.title" in
//															functions "ShowSelectedPhoto()" and
//															"ShowPhoto()" to view alt-texts in IE8.
//*************************************************************************************************

//Array declarations
var ScrRes		= new Array(0.65,1.05,1.28,1.44);				// Zoom factors (4 selections).
																// 0.65=  800x600  screen size.
																// 1.05= 1024x768  screen size.
																// 1.28= 1152x864  screen size.
																// 1.44= 1280x960  screen size.
																// 1.44= 1280x1024 screen size.
																// 1.44= 1600x1200 screen size.
var PhotoBuffer	= new Array(LastPhotoNumber + 1);

//Initialisation of variables
ZoomOutDummy		=	"Images/Zoom_out.jpg";
PhotoDelay			=	100;									// In milliseconds.
PhotoCounter		=	  1;
MaxPhotoHeight		=	400; 									// In pixels.
ScrResCounter		=	  1;									// Initial zoom factor selection.
ScrResFactor		= ScrRes[ScrResCounter];					// Selected zoom factor.

//Global Screenheight function; will be executed immediately after script startup!!
//Function is used to determine the used screen settings of the viewer.
ScrHeight = screen.height;
switch (ScrHeight) {
	case 600 :{
			ScrResCounter = 0;
			break;
			}
	case 768 : {
			ScrResCounter = 1;
			break;
			}
	case 864 : {
			ScrResCounter = 2;
			break;
			}
	case 960 : {
			ScrResCounter = 3;
			break;
			}
	case 1024 : {
			ScrResCounter = 3;
			break;
			}
	case 1200 : {
			ScrResCounter = 3;
			break;
			}
	default  : {
			ScrResCounter = 1;
			}
}
ScrResFactor = ScrRes[ScrResCounter];
			
//Function definitions
function ShowSelectedPhoto()	{
		document.write('<img name="CurrentPhoto">');
		document.CurrentPhoto.src= PhotoSource[PhotoCounter];
		document.CurrentPhoto.alt= PhotoText[PhotoCounter];
		document.CurrentPhoto.title= PhotoText[PhotoCounter];
		ScaleFactor= MaxPhotoHeight / PhotoHeight[PhotoCounter];
		document.CurrentPhoto.width	= PhotoWidth[PhotoCounter]  * ScrResFactor * ScaleFactor;
		document.CurrentPhoto.height= PhotoHeight[PhotoCounter] * ScrResFactor * ScaleFactor;
}

function NextPhoto()	{
		if (PhotoCounter == LastPhotoNumber) {
			PhotoCounter= FirstPhotoNumber;
			}
		else {
			PhotoCounter= PhotoCounter + 1;
		}
		ResetPhoto();
		setTimeout("ShowPhoto()",PhotoDelay);
}

function PrevPhoto()	{
		if (PhotoCounter == FirstPhotoNumber) {
			PhotoCounter= LastPhotoNumber;
			}
		else {
			PhotoCounter= PhotoCounter - 1;
		}
		ResetPhoto();
		setTimeout("ShowPhoto()",PhotoDelay);
}

function ResetPhoto() {
		ScaleFactor= MaxPhotoHeight / PhotoHeight[PhotoCounter];
		document.CurrentPhoto.src= ZoomOutDummy;
		document.CurrentPhoto.width	= 10;
		document.CurrentPhoto.height= PhotoHeight[PhotoCounter] * ScrResFactor * ScaleFactor;
		document.all.TextLeft.innerHTML= '[Loading]';
		document.all.TextRight.innerHTML= '';
}

function ShowPhoto() {
		ScaleFactor= MaxPhotoHeight / PhotoHeight[PhotoCounter];
		document.CurrentPhoto.width	= PhotoWidth[PhotoCounter] * ScrResFactor * ScaleFactor;
		document.CurrentPhoto.height= PhotoHeight[PhotoCounter]* ScrResFactor * ScaleFactor;
		document.CurrentPhoto.src= PhotoSource[PhotoCounter];
		document.CurrentPhoto.alt= PhotoText[PhotoCounter];
		document.CurrentPhoto.title= PhotoText[PhotoCounter];
		document.all.TextLeft.innerHTML= PhotoSubscript[PhotoCounter] + '...';
		document.all.TextRight.innerHTML= Photographer[PhotoCounter] + '.';
		window.status= "";
}

function ScreenRes()	{
		if (ScrResCounter == ScrRes.length - 1) {
			ScrResCounter= 0;
			}
		else {
			ScrResCounter= ScrResCounter + 1;
		}
		ScrResFactor=ScrRes[ScrResCounter];
		ShowPhoto();
}

function PreLoadPhotos()	{
	PhotoZoom		= new Image();
	PhotoZoom.src	= ZoomOutDummy;
	for (DimCntr = 1; DimCntr <= LastPhotoNumber; DimCntr++)	{
		PhotoBuffer[DimCntr] 		= new Image();
		PhotoBuffer[DimCntr].src	= PhotoSource[DimCntr];
		}
}