// Global variable
var oldID;

function loadFirstPhoto() {
	// Check if the first photo is in the category
	firstPhoto	=	document.getElementById('photo_1');
	if(typeof(firstPhoto) != "undefined") {
		showPhoto('0');	
	}
}

////////////////////////////////////////////////////////////////
// BEGIN Show photo functions
function showPhoto(id) {
	// Hide image
	new Effect.Fade('photo_img', {duration: 0.3, afterFinish: function(){	loadImage(photos[id]); } });
	// Change the thumb class
	changeThumb(oldID, id);
	
	// change the old ID
	oldID = id;
}

function loadImage(newPhoto) {
	imgPreloader = new Image();

	// once image is preloaded, resize image container
	imgPreloader.onload=function(){
		document.getElementById('photo_img').src	=	newPhoto;
		showImage();
		imgPreloader.onload=function(){};	//	clear onLoad, IE behaves irratically with animated gifs otherwise 
	}
	imgPreloader.src = newPhoto;	
}

function showImage() {
	new Effect.Appear('photo_img', {duration: 0.3});
}

function changeThumb(oldID, newID) {
	// Check if the oldID is set
	// Do things with the new photo
	document.getElementById('photo'+newID).style.background	= "#1b4670";
	if(typeof(oldID) != "undefined"  ) {
		new Effect.Highlight('photo'+oldID, {startcolor:'#1b4670', endcolor:'#FFFFFF', afterFinish: function() { 
																											 document.getElementById('photo'+oldID).style.background	= "#FFFFFF"; 
																											 } });
	}
}

function hoverPhotoIn(id) {
	document.getElementById('photo'+id).style.background	= "#1b4670";
}

function hoverPhotoOut(id) {
	// Check if the photo is not selected
	if(id != oldID) {
		document.getElementById('photo'+id).style.background	= "#FFFFFF";
	}
}

// END Hhow photo functions
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
// BEGIN NEXT-PREV functions

function nextPhoto() {
	id	=	oldID;
	
	if(typeof(id) != "undefined"  ) {

		if(id >= totalPics) {
			// do nothing
		} else {
			showPhoto(++id);
		}
		
	} else {
		showPhoto('0');
	}
}

function prevPhoto() {
	id	=	oldID;
	
	if(typeof(id) != "undefined"  ) {

		if(id <= '0') {
			// Do nothing
		} else {
			showPhoto(--id);
		}
		
	} else {
		showPhoto('0');
	}	
}


// END NEXT-PREV functions
////////////////////////////////////////////////////////////////