// Slideshow created with MooTools

//Settings
var currentImage = 0; //First image to load
var slideshowDelay = 5000;
var fadeDuration = 2500;
var matchDimensions = true;
var matchWidth = true; //match the photo width
var matchHeight = false; //match the photo height
var images = []; //id, photo, width, height

images[0] = new Array('photo1','resources/images/photos/new/4.jpg', '350px', '260px');
images[1] = new Array('photo2','resources/images/photos/1.jpg', '248px', '311px');
images[2] = new Array('photo3','resources/images/photos/4.jpg', '324px', '379px');
images[3] = new Array('photo4','resources/images/photos/5.jpg', '296px', '480px');
images[4] = new Array('photo5','resources/images/photos/msohn.jpg', '311px', '368px');
images[5] = new Array('photo6','resources/images/photos/6.jpg', '331px', '368px');
images[6] = new Array('photo7','resources/images/photos/new/3.jpg', '339px', '331px');
//images[7] = new Array('photo8','resources/images/photos/msohn2.jpg', '356px', '260px');
images[7] = new Array('photo8','resources/images/photos/7.jpg', '350px', '296px');
images[8] = new Array('photo9','resources/images/photos/new/2.jpg', '304px', '327px');
images[9] = new Array('photo10','resources/images/photos/11.jpg', '350px', '527px');

var showWidth = images[currentImage][0];
var showHeight = images[currentImage][3];

//Begin Functions

function initSlideshow(){
	addImages(images);
	
	//Hide all other images except for the currentImage
	for(k=0;k<images.length;k++){
		if(k != currentImage) Hide(images[k][0]);
	}
	
	if(matchDimensions) SlideshowDimensions();
	
	setTimeout('nextImage()', slideshowDelay);
}

function nextImage(){
	FadeOut(images[currentImage][0]);
	
	//update the current width so the dimensions transition will move smoothly.
	showWidth = images[currentImage][2];
	showHeight = images[currentImage][3];
	
	if(currentImage < images.length-1) {
		currentImage = currentImage+1;
	}else{
		currentImage = 0;
	}
	
	FadeIn(images[currentImage][0]);
	
	//Set timeout for next image to show
	setTimeout('nextImage()', slideshowDelay);
}

function FadeIn(id){
	var fadeIn = new Fx.Style(id, 'opacity', {duration:fadeDuration}).start(0,1);
	
	if(matchDimensions) SlideshowDimensions();
}

function FadeOut(id){
	var fadeOut = new Fx.Style(id, 'opacity', {duration:fadeDuration}).start(1,0);
}

function Hide(id){
	var hide = new Fx.Style(id, 'opacity').set(0);
}

function SlideshowDimensions(){
	if(matchWidth) var newWidth = new Fx.Style('Slideshow', 'width').start(showWidth, images[currentImage][2]);
	if(matchHeight) var newHeight = new Fx.Style('Slideshow', 'height').start(showHeight, images[currentImage][3]);
}

function addImages(arrImages) {
	for(i=0;i<arrImages.length;i++){
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id',arrImages[i][0]);
		newdiv.style.zIndex = (arrImages.length-i)+10;
		newdiv.innerHTML = '<img src="' + arrImages[i][1] + '" />';
		document.getElementById('Slideshow').appendChild(newdiv);
		
		newdiv.style['position'] = 'absolute';
		newdiv.style['top'] = '0px';
		newdiv.style['left'] = '0px';
		newdiv.style['margin'] = 'auto';
	}
}
