Event.observe(window,'load',function(){
	slideshowInit();
});

// Current Page & images folder?
var currentPage = document.location.href.substr(document.location.href.lastIndexOf("/")+1);
var imagesFolder = currentPage.split('.')['0'];

var iThumb = 1;

function slideshowInit(){

	//Build Containers
	var objSlideshowContainer = document.createElement("div");
	
	// Build Default Image Container
	var objImageContainer = document.createElement("div");
	objImageContainer.setAttribute('id','imageContainer');
	objSlideshowContainer.appendChild(objImageContainer);
	Element.extend(objImageContainer);
	
	//alert('load ' + imagesFolder + '/image1.jpg');
	
	
	var url = imagesFolder+'/image1.jpg';
	
	var image = new Image();
	image.setAttribute('id','mainImage');
	Element.extend(image);
	image.hide();
	image.onload = function(){ 
		objImageContainer.appendChild(this);
		new Effect.Appear(this);
	}
	image.src = imagesFolder + '/image1.jpg';
	
	// Build Thumbs Container
	var objThumbsContainer = document.createElement("div");
	objThumbsContainer.setAttribute('id','thumbsContainer');
	objSlideshowContainer.appendChild(objThumbsContainer);
	
	$('slideshow').update(objSlideshowContainer);
	
	// Load Thumbs
	loadThumb(iThumb);

}

function loadThumb(){

	var objThumbContainer = document.createElement("div");
	objThumbContainer.className = 'thumb';
	objThumbContainer.setAttribute('id','change' + iThumb);
	
	var thumb = new Image();
	thumb.setAttribute('id','thumb' + iThumb);
	Element.extend(thumb);
	thumb.hide();
	thumb.onload = function(){
		objThumbContainer.appendChild(this);
		new Effect.Appear(this); 
		objThumbContainer.onmouseover = function(){
			loadImage(this.id);
		}
		$('thumbsContainer').appendChild(objThumbContainer);
		loadThumb(iThumb++);
	}
	thumb.src = imagesFolder+'/thumb' + iThumb + '.jpg';
	
	
}

function loadImage(iImage){
	
	iImage = iImage.split('change')['1'];
	$('mainImage').src = imagesFolder+'/image' + iImage + '.jpg';

}