var CurrentPhoto = 1;
var PhotoAlbumPhotosCount = 0;
var Delay = 3500;
var PhotoAlbumID = 0;
var Running = false;
var EndTime = null;
var TimerID = null;

function init(thisPhotoAlbumPhotosCount, thisPhotoAlbumID)
{
	PhotoAlbumPhotosCount = thisPhotoAlbumPhotosCount;
	PhotoAlbumID = thisPhotoAlbumID;
	document.Abroadco = new Object();
	document.Abroadco.LoadedImages = new Array();
	for(x=1; x<PhotoAlbumPhotosCount; x++)
	{
		document.Abroadco.LoadedImages[x] = new Image();
		document.Abroadco.LoadedImages[x].src = "../Images/PhotoAlbums/" + PhotoAlbumID + "/" + x + ".jpg";
	}
	document.getElementById('PhotoCaption1').className='PhotoCaption';
}

function Change(NextPhoto)
{
	document.getElementById('PhotoCaption' + CurrentPhoto).className='PhotoCaptionInvisible';
	CurrentPhoto = CurrentPhoto + NextPhoto;
	if(CurrentPhoto == 0)
		CurrentPhoto = PhotoAlbumPhotosCount;
	if(CurrentPhoto == PhotoAlbumPhotosCount + 1)
		CurrentPhoto = 1;
	document.images['PhotoAlbum'].src = "../Images/PhotoAlbums/" + PhotoAlbumID + "/" + CurrentPhoto + ".jpg";
	document.getElementById('PhotoCaption' + CurrentPhoto).className='PhotoCaption';
}

function Play()
{
	Running = true;
	VisibilitySwitch('Invisible', 'Visible');
	var Now = new Date();
	Now = Now.getTime();
	EndTime = Now + Delay;
	CheckTimer();
}

function Stop()
{
	Running = false;
	VisibilitySwitch('Visible', 'Invisible');
	var Now = new Date();
	Now = Now.getTime();
	EndTime = Now + Delay;
	CheckTimer();
}

function CheckTimer()
{
	var Now = new Date();
	Now = Now.getTime();
	if(EndTime - Now <= 0)
	{
		Change(+1);
		Play();
	}
	else
		if(Running)
			TimerID = setTimeout("CheckTimer()", 125);
}

function Email()
{
	top.location.href = "./PhotoAlbumEmail-" + CurrentPhoto + ".htm";
}

function ToolbarRoll(Role, Action)
{
	if(Running)
	{
		if(Role == 'Stop')
			document.images[Role].src = "../Images/Programs/PhotoAlbum/" + Action + "/" + Role + ".jpg";
	}
	else
	{
		if(Role != 'Stop')
			document.images[Role].src = "../Images/Programs/PhotoAlbum/" + Action + "/" + Role + ".jpg";
	}
}

function VisibilitySwitch(LinkClass, TextClass)
{
	document.getElementById('ToolbarPlayLink').className=LinkClass;
	document.getElementById('ToolbarPlayText').className=TextClass;
	document.getElementById('ToolbarStopLink').className=TextClass;
	document.getElementById('ToolbarStopText').className=LinkClass;
	document.getElementById('ToolbarPreviousLink').className=LinkClass;
	document.getElementById('ToolbarPreviousText').className=TextClass;
	document.getElementById('ToolbarNextLink').className=LinkClass;
	document.getElementById('ToolbarNextText').className=TextClass;
	document.getElementById('ToolbarEmailLink').className=LinkClass;
	document.getElementById('ToolbarEmailText').className=TextClass;
}