function changeOpacity(id, value) {
	if (document.all && !window.opera) document.getElementById(id).style.filter='alpha(opacity='+value*100+')';
	else document.getElementById(id).style.opacity=value;
}

var Photo = function(source, caption) {
	this.img = new Image();
	this.isLoaded = false;
	this.loadingTime = null;
	this.src = source;
	this.load = function() {
		var loadingStarted = new Date().getTime();
		this.img.src = this.src;
		this.img.alt = caption;
		this.img.title = caption;
		this.img.id = 'photoOfTheDay';
		this.img.style.filter = 'alpha(opacity=0)';
		this.img.style.opacity = 0;
		photoObj = this;
		this.img.onload = function() {
			photoObj.isLoaded = true;
			var now = new Date().getTime();
			photoObj.loadingTime = parseInt(now) - parseInt(loadingStarted);
		}
	}
}

var flashingPhotos = {
	currentPhoto: 0,
	delay: 5000,
	loadNext: function() {
		flashingPhotos.currentPhoto = (flashingPhotos.currentPhoto<photos.length-1) ? this.currentPhoto+1 : 0;
		if(!photos[flashingPhotos.currentPhoto].isLoaded) photos[flashingPhotos.currentPhoto].load();
	},
	showNext: function() {
		flashingPhotos.loadNext();
		if((flashingPhotos.delay-photos[flashingPhotos.currentPhoto].loadingTime)>0) {	localDelay = flashingPhotos.delay-photos[flashingPhotos.currentPhoto].loadingTime}
		else {localDelay = flashingPhotos.delay;}
		setTimeout(function() { flashingPhotos.flash(); }, localDelay);
		
	},
	flash: function() {
		document.getElementById('photoOfTheDayPlacer').replaceChild(photos[flashingPhotos.currentPhoto].img, document.getElementById('photoOfTheDay'));
		for (i=0; i<11; i++) setTimeout('changeOpacity("photoOfTheDay", '+i/10+')', i*50);
		var previous = (flashingPhotos.currentPhoto>0) ? flashingPhotos.currentPhoto-1 : photos.length-1;
		photos[previous].img.style.filter = 'alpha(opacity=0)';
		photos[previous].img.style.opacity = 0;
		flashingPhotos.showNext();
	}
}


window.onload = function() {
	photos[0].load();
	flashingPhotos.showNext();
}

