//
// JavaScript for Slide Show page. by janlay.
//
var img, photoArea;
var theTimer = -1;
var count = 0, index = 0;
var stopped = false;
var hour = (new Date()).getHours();

var arrPhotos = new Array();
var arrpreloadPhotos = new Array();

function Photo(photoId, caption, uri)
{
	if(arguments.length == 0)
	{
		alert('Could not create Photo without properties.');
		return false;
	}
	
	this.PhotoID = photoId;
	this.Caption = caption;
	this.Uri = uri;
	
	this.IsLoaded = false;
}

function preloadPhotos()
{
	for (var i = 0; i < count; i++)
	{
		var img = new Image();
		img.src = arrPhotos[i].Uri;
		img.onload = new Function('markLoaded(' + i + ')');
		
		arrpreloadPhotos[i] = img;
	}
}

function markLoaded(num)
{
	var o = arrPhotos[num];
	if(o)
		o.IsLoaded = true;
}

function play()
{
	var p = arrPhotos[index];
	
	
    if(count > 1)
	{
		theTimer = setTimeout("play()", 6000);
	}
	
	if(photoArea.filters)
		photoArea.filters[0].Apply();
	
	var html = '<a href="' + urlPattern + p.PhotoID + '" target="_blank"><img src="' + arrPhotos[index].Uri + '" vspace="10" class="big_photo" /></a><div class="PhotoCaption">[' + (index + 1) + '/' + count + '] ' + p.Caption +'</div>';
	
	if(photoArea.filters)
		photoArea.filters[0].Play();
	photoArea.innerHTML = html;
	
	if(++index == count)
		index = 0;
}

function stop()
{
	if(theTimer)
		clearTimeout(theTimer);

	stopped = true;
}

function init()
{
	photoArea = document.getElementById('PhotoArea');
	if(!photoArea)
	{ alert('Failed to locate photo area'); return; }
		
	count = arrPhotos.length;
	preloadPhotos();
	play();
}

Event.observe(window, 'load', init);
