window.onload = function() {
	var imgH = 75 +5; //img height + margin
	var preview = $('#preview');
	var thumbs = $('#thumbs');
	var anchors = $('#thumbs a');
	var preview2 = $('#preview2');
	var thumbs2 = $('#thumbs2');
	var anchors2 = $('#thumbs2 a');
	var animSpeed = 2500;
	var animDelay = 5000;
	pause = false;
	direction = -1;
	
	//hover
	anchors.mouseover(function(){
		preview.html( $(this).html() );
		preview.removeClass("hidden");
		//preview.fadeIn(300);
		preview.show();
		pause = true;
    });
	
	anchors.mouseout(function(){
		//preview.fadeOut(10);
		preview.hide();
		preview.html('');
		preview.addClass("hidden");
		pause = false;
    });
	anchors2.mouseover(function(){
		preview2.html( $(this).html() );
		preview2.removeClass("hidden");
		//preview2.fadeIn(300);
		preview2.show();
		preview2.css({left: -preview2.width()});
		//console.log();
		pause = true;
    });
	
	anchors2.mouseout(function(){
		//preview2.fadeOut(10);
		preview2.hide();
		preview2.html('');
		preview2.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
		thumbs2.animate(
			{ top: d+'px'}, 
			animSpeed, 
			"swing", 
			function() { //callback		
				if(direction < 0) {
					$('#thumbs2 a:first').appendTo(thumbs2);
				}
				else if (direction > 0) {
					$('#thumbs2 a:last').prependTo(thumbs2);
				}
				thumbs2.css('top', '0px');
			}
		  )
		 //end animate
	} //end move
	
	//Move
	$("#thumbs-prev").click( function(){ 
		direction = -1;
		move(-1);
	});
	$("#thumbs-next").click( function(){ 
		direction = 1;
		move(1);
	});
	$("#thumbs-prev2").click( function(){ 
		direction = -1;
		move(-1);
	});
	$("#thumbs-next2").click( function(){ 
		direction = 1;
		move(1);
	});
	var timer = self.setInterval("if (!pause) {move(direction)}",animDelay);
}

