var galleryHeight = 205;
var currentImage = 0;
var currentOffset = 0;
var timeout = 4500;

var gallery;
var images;


function startGallery() {
	
	
	
	gallery = document.getElementById('galleryholder');
	if (gallery != null) {
	
		images = gallery.getElementsByTagName('img');
		
		
		
		if (images.length > 1) {
		
			if (images[currentImage].height > galleryHeight) {
				// start a horizontal show all interval first
				setTimeout("showVerticalImage()", 500);
			} else {
				// wait and to to the next image
				
				setTimeout("nextImage()", timeout);
			}
			
		} else {
			if (images[currentImage].height > galleryHeight) {
				// start a horizontal show all interval first
				setTimeout("showVerticalImage()", 500);
			}
		}
	}
}

function showVerticalImage() {
	offset = images[currentImage].height - galleryHeight;
	currentOffset = currentOffset - offset;
	
	var myFx = new Fx.Tween(gallery, {duration: '3500', transition: Fx.Transitions.Cubic.easeInOut});
	myFx.start('top', currentOffset);
	
	setTimeout("nextImage()", 4500);
}

function nextImage() {
	
	if (currentImage < images.length - 1) {
		currentOffset = currentOffset - galleryHeight;
	
		var myFx = new Fx.Tween(gallery, {duration: '500', transition: Fx.Transitions.Cubic.easeInOut});
		myFx.start('top', currentOffset);
	
		currentImage++;
	
		if (images[currentImage].height > galleryHeight) {
			
			// start a horizontal show all interval first
			setTimeout("showVerticalImage()", 500);
		} else {
			setTimeout("nextImage()", timeout);
		}
	} else {
		setTimeout("goUpAgain()", timeout);
	}
	
	
	
}

function goUpAgain() {
	currentImage = 0;
	currentOffset = 0;
	
	var myFx = new Fx.Tween(gallery, {duration: '500', transition: Fx.Transitions.Cubic.easeInOut});
	myFx.start('top', currentOffset);
	
	if (images[currentImage].height > galleryHeight) {
		// start a horizontal show all interval first
		setTimeout("showVerticalImage()", 500);
	} else {
		setTimeout("nextImage()", timeout);
	}
}
