// JavaScript Document
$(document).ready(function() {
//THUMBS CODE						   
	$('.thumb').animate({'opacity':'.5'});
	$('.thumb').mouseenter(function() {
		$(this).animate({'opacity':'1'});
	}).mouseleave(function() {
		$(this).animate({'opacity':'.5'});
	});
	$('.thumb').click(function() {
		var source = $(this).attr('src').replace('small','large');
		$('#main-picture img').fadeOut('fast');
		$('#main-picture img').attr({src:source});
		$('#main-picture img').load(function(){
			$('#main-picture img').fadeIn('fast');
		});
   	});

//MOVEMENT CODE
	var thumbHeight = $('#move-thumbs').height();
	var maxThumbTop = 0;
	var thumbPos;
	var count=1;
	var topPosition =0;
	var imagePosition = 0;
	var prevY;
	var topPos;
	var y;
	var distance;
	var yExp;
	
	$('#move-thumbs').height(thumbHeight);
	
	maxThumbTop = thumbHeight - 400;
	maxThumbTop = -maxThumbTop;  

	$("#scroll-container").mousemove(function(e){
		y = e.pageY - this.offsetTop;
		if(y > 250) {
			yExp = (y-250) / 80;
			distance = Math.exp(yExp);
			distance = Math.round(distance);
		} else if(y < 150) {
			yExp = (0-(y-150)) / 80;
			distance = Math.exp(yExp);
			distance = Math.round(distance);
		}
   });
	
	setInterval(movePosition,40);

	function movePosition() {
		topPos = $('#move-thumbs').css('top').replace('px','');
		if (y < 150 || y > 250) {
			if (y <150 && topPos <0) {
					$('#move-thumbs').css({
								  top: (topPos - -distance) + 'px'
								  });
			}
			if (y >250 && topPos > maxThumbTop) {
					$('#move-thumbs').css({
										  top: (topPos - distance) + 'px'
										  });
			}
		}
		prevY = y;
	}

 });
