ThumbnailSlider = {

	init: function() {
		//don't show thumbs if there is only one image
		if($('#image-thumbs .thumb-holder').length>1){
		$('#image-thumbs').show();
		var sliderWidth=$('#image-thumbs').width();
		var itemWidth=parseInt($('.thumb-holder').css("width"));
		var totalContent;
		var targetThumbX=0;
		$('#image-thumbs .thumb-holder').each(function (i) {
				totalContent=i*itemWidth;	
				$('#image-thumbs #image-thumbs-holder').css("width",totalContent+itemWidth);
		});
		$("div#image-thumbs-holder a").click(function() {
			Gallery.gotoImage($("div#image-thumbs-holder a").index(this));
			return false;
		});
		//don't scroll thumbs if they dont extend past the visible area
		if(totalContent>sliderWidth-itemWidth){
		//make total content a little larger so it is easier to click on first and last thumbnails
		totalContent=totalContent+itemWidth+itemWidth;
		
		window.setInterval(function() {
			var cx=parseInt($('#image-thumbs #image-thumbs-holder').css('left'));
			var difx=cx-targetThumbX;
			var amountToMove=difx/5;
			var t=cx-amountToMove;
		  $('#image-thumbs #image-thumbs-holder').css('left',t);
		//$("p:last").html(targetThumbX);
		}, 50);
	
		$('#image-thumbs').mousemove(function(e){
			 // var mouseCoords=(e.pageX - this.offsetLeft);
			
			// cross-browser mouse position calculation
			var posx = 0;
			if (!e) var e = window.event;

			if (e.pageX) { posx = e.pageX; }
			else if (e.clientX) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; }

			// recalculate mouse position relative to the wrapping div
			var mouseCoords = posx - $('#image-thumbs').offset().left;
			
			
			  var mousePercentY=mouseCoords/sliderWidth;
		
			  var destX=itemWidth-(((totalContent-(sliderWidth-itemWidth))-sliderWidth)*(mousePercentY));
			  var thePosA=mouseCoords-destX;
			  var thePosB=destX-mouseCoords;
			  if(mouseCoords==destX){
				  $('#image-thumbs #image-thumbs-holder').stop();
			  }
			  if(mouseCoords>destX){
				  targetThumbX=-thePosA;
			  }
			  if(mouseCoords<destX){
				 targetThumbX=thePosB;
			
			  }
			
		
		});
		}
		}
	}
}