// JavaScript Document
$(document).ready(function() {
	var count = 0;
	var rollID;
	var clickSrc;
	var overWidth = $('#gallery-inner').width();
	overWidth = (overWidth -150) / 4;
	origWidth = $('.thumb').width();
  	var countThumbs = $('#move-thumbs > *').length;
	countThumbs = (countThumbs * origWidth)+10;
	
	$('#move-thumbs').width(countThumbs)


	$('#move-thumbs div').each(function(index) {
		$(this).attr({
			'id' : 'thumb-'+ index
		});
	});
	
	$('.thumb').mouseenter(function(){
		rollID = $(this).attr('id');
		$('#'+rollID).stop().animate({
		  'width':'150px'
		});
		if($('.thumb')) {
			for(var i=0;i<5;i++) {
				rollID = rollID.replace('thumb-','');
				if(count!=rollID) {
					$('#thumb-'+count).stop().animate({
						'width': overWidth + 'px'
					});
				}
				count++;
			}
			count=0;
		}
	});
	$('#move-thumbs').mouseleave(function(){
		$('.thumb').stop().animate({
			'width':origWidth+'px'
		});
	});
	
	$('.thumb').click(function(){
		clickSrc= $(this).children().attr('src').replace('thumbs','large');
		$('#gallery-image').children('img').fadeOut();
		setTimeout(nameMeIn, 520)
		
		function nameMeIn() {
			$('#gallery-image').children('img').attr({'src':clickSrc});
			setTimeout(fadeMeIn, 100)
		};
		
		function fadeMeIn() {
			$('#gallery-image').children('img').fadeIn();
		};
	});
	
});

