// JavaScript Document
$(document).ready(function() {
	var id = 'thumb-0';	
	
//THUMBS CODE						   
	$('.thumb2').animate({'opacity':'.5'});
	$('.thumb2').mouseenter(function() {
		$(this).animate({'opacity':'1'});
	}).mouseleave(function() {
		$(this).animate({'opacity':'.5'});
	});
	$('.thumb2').click(function() {
		var source = $(this).attr('src').replace('small','large');
		$('#main-press img').fadeOut('fast');
		$('#main-press img').attr({src:source});
		$('#main-press img').load(function(){
			$('#main-press img').fadeIn('fast');
		});
		$('.'+id).css({'display':'none'});
		id = $(this).attr('id');
		$('.'+id).css({'display':'block'});
   	});

//MOVEMENT CODE
  // put all your jQuery goodness in here.
  var countThumbs = $('#move-thumbs-press > *').length;
  var thumbWidth = 0;
  var maxThumbLeft = 0;
  var thumbPos;
  var count=0;
  var imageWidth;
  var imageHeight;
  var topPosition =0;
  var imagePosition = 0;
  var thumbArray = new Array(countThumbs);
  var prevX;
  var leftPos;
  var x;
  var y;
  var distance;
  var xExp;
  
  $('#move-thumbs-press img').each(function(index) {
		$(this).attr({
			'id' : 'thumb-'+ index
		});
	});
	
	for (var i=0; i<countThumbs; i++) {
	  thumbArray[i] = $('#thumb-'+count).width() + 1;
	  thumbWidth = thumbWidth + thumbArray[i];
	  count++;
  }
  
  maxThumbLeft = thumbWidth - 520;
  maxThumbLeft = -maxThumbLeft;  
  
	$('#move-thumbs-press').animate({ 
        width: thumbWidth + 'px'
      });
	
	$("#scroll-container-press").mousemove(function(e){
		x = e.pageX - this.offsetLeft;
		y = e.pageY - this.offsetTop;
		
		if(x > 310) {
			xExp = (x-310) / 80;
			distance = Math.exp(xExp);
			distance = Math.round(distance);
		} else if(x <260) {
			xExp = (0-(x-260)) / 80;
			distance = Math.exp(xExp);
			distance = Math.round(distance);
		}
   });
	
	setInterval(movePosition,40);

	function movePosition() {
		leftPos = $('#move-thumbs-press').css('left').replace('px','');
		if (x < 260 || x > 310) {
			if (x <260 && leftPos <0) {
					$('#move-thumbs-press').css({
								  left: (leftPos - -distance) + 'px'
								  });
			}
			if (x >310 && leftPos > maxThumbLeft) {
					$('#move-thumbs-press').css({
										  left: (leftPos - distance) + 'px'
										  });
			}
		}
		prevX = x;
	}

 });
