/* Slideshow with dissolve */

var slides = new Array();

slides[0] = 'images/photo10.jpg';
slides[1] = 'images/photo11.jpg';
slides[2] = 'images/photo21.jpg';
slides[3] = 'images/photo12.jpg';
slides[4] = 'images/photo20.jpg';
slides[5] = 'images/photo02.jpg';
slides[6] = 'images/photo05.jpg';
slides[7] = 'images/photo08.jpg';
slides[8] = 'images/photo09.jpg';
slides[9] = 'images/photo16.jpg';
slides[10] = 'images/photo24.jpg';
slides[11] = 'images/photo23.jpg';
slides[12] = 'images/photo06.jpg';
slides[13] = 'images/photo01.jpg';
slides[14] = 'images/photo25.jpg';
slides[15] = 'images/photo18.jpg';

// Dimension of each slide
var slideWidth = 744;
var slideHeight = 314;

// Fade rate between slides
var dissolveRate = 25;

// How long each slide is on the screen.
var slideDuration = 4;

// Text to display the number of currently loaded images and the number loaded.
var preloadtext = 'Loading |loaded| of |total|';

// Don't mess around below this line.

// Which browser are you using?
var mozilla = (document.getElementById && !document.all) ? 1:0;
var safari = (navigator.userAgent.indexOf('AppleWebKit') >= 0) ? 1:0;
var ie = (document.getElementById && document.all) ? 1:0;

// Get the alpha of an object.
function getAlpha(obj) {
if (mozilla) {
	theAlpha = document.getElementById(obj).style.opacity * 100;
	}
else if (safari) {
	theAlpha = document.getElementById(obj).style.opacity * 100;
	}
else if (ie) {
	theAlpha = document.getElementById(obj).filters.alpha.opacity;
	}
return theAlpha;
}

// Advances the slides
function switchSlides(index) {
slideCount = slides.length;
if (index == (slideCount -1)) {
	nextIndex = 0;
	}
else {
	nextIndex = index + 1;
	}
document.getElementById('slide').style.backgroundImage = 'url('+ slides[(index)] +')';
setTimeout("document.getElementById('slideshow').style.backgroundImage = 'url('+ slides[(nextIndex)] +')'",20);
setTimeout("dissolve('slide', nextIndex)",20);
setAlpha('slide',100);
}

// Sets the alpha of a given object
function setAlpha(obj, value) {
if (mozilla) {
	document.getElementById(obj).style.opacity = (value / 100);
	}
else if (safari) {
	document.getElementById(obj).style.opacity = (value / 100);
	}
else if (ie) {
	document.getElementById(obj).filters.alpha.opacity = value;
	}
}

slideDuration = slideDuration * 1000; //milliseconds 
var dissolveTimer = ''; 

// Dissolve one slide to another. 
function dissolve(obj, currIndex) {
theSlide = obj;
theIndex = currIndex
theAlpha = getAlpha('slide');
if (theAlpha > 0) {
	setAlpha('slide', (theAlpha - 5));
	dissolveTimer = window.setTimeout("dissolve(theSlide, theIndex)",dissolveRate);
	}
else {
	window.clearTimeout(dissolveTimer);
	window.setTimeout("switchSlides(theIndex)",slideDuration);
	}
}

function slideshow() {
	window.setTimeout("switchSlides(0)",slideDuration);
	}

// Preloading array
var preload = new Array();
preload['loaded'] = new Array();
preload['loading'] = new Array();
var currCount = 0, slideTimer = '';

function startSlideshow() {
	if (ie) {
		document.getElementById('slideshow').innerHTML = '<div id="slide" style="filter: alpha(Opacity: 100)"></div>';
		document.getElementById('slide').filters.alpha.opacity = 100;
		}
	else {
		document.getElementById('slideshow').innerHTML = '<div id="slide"></div>';
		document.getElementById('slide').style.opacity = 1;
		}
	document.getElementById('slide').style.width = document.getElementById('slideshow').offsetWidth +'px';
	document.getElementById('slide').style.height = document.getElementById('slideshow').offsetHeight +'px';
	document.getElementById('slideshow').style.background = 'url('+ slides[0] +')';
	for (i = 0; i < slides.length; i++) { 
		preload['loading'][i] = new Image();
		preload['loading'][i].src = slides[i];
		}
	for (i=0;i<preload['loading'].length;i++) {
		preload['loaded'][i] = false;
		}
	checkLoad();
	}

/*var loaderdiv = '<div id="loader" style="display: inline; width: 150px; font-family: Arial, Sans-serif; font-size: 11px; color: #683825; background: #f5f5ed; padding: 1px">|loadingtext|</div>';*/

var loaderdiv = '<div id="loader" style="display: none"></div>';

function checkLoad() {
pt = preloadtext.replace('|loaded|', currCount);
pt = pt.replace('|total|', slides.length);
ld = loaderdiv.replace('|loadingtext|', pt);
document.getElementById('slide').innerHTML = ld;
if (currCount == preload['loading'].length) {
	document.getElementById('loader').style.display = 'none';
	slideshow();
	return
	}
for (i=0;i<preload['loading'].length;i++) {
	if (preload['loaded'][i] == false && preload['loading'][i].complete) {
		preload['loaded'][i] = true;
		currCount++;
		}
	}
slideTimer = setTimeout("checkLoad()",10);
}

window.onload = function() { startSlideshow(); }