window.onload = function() {
	var imgH = 75 +5; //img height + margin
	var preview = $('#preview');
	var thumbs = $('#thumbs');
	var anchors = $('#thumbs a');
	var animSpeed = 1000;
	var animDelay = 3000;
	pause = false;
	direction = -1;
	
	//hover
	anchors.mouseover(function(){
		preview.html( $(this).html() );
		preview.removeClass("hidden");
		preview.fadeIn(300);
		pause = true;
    });
	
	anchors.mouseout(function(){
		preview.fadeOut(10);
		preview.html('');
		preview.addClass("hidden");
		pause = false;
    });
	
	move = function(direction) {
		var d = 0 + direction*imgH;
		thumbs.animate(
			{ top: d+'px'}, 
			animSpeed, 
			"swing", 
			function() { //callback
				if(direction < 0) {
					$('#thumbs a:first').appendTo(thumbs);
				}
				else if (direction > 0) {
					$('#thumbs a:last').prependTo(thumbs);
				}
				thumbs.css('top', '0px');
			}
		) //end animate
	} //end move
	
	//Move
	$("#thumbs-prev").click( function(){ 
		direction = -1;
		move(-1);
	});
	$("#thumbs-next").click( function(){ 
		direction = 1;
		move(1);
	});
	var timer = self.setInterval("if (!pause) {move(direction)}",animDelay);
}