$(window).load(function() {
		// set intial width of gallery to larger than widths of images
		$('.gallery').css({
			left: -250,
			width: 10000
		})

		// initial position of gallery
		$('.gallery').animate({left: "-15px"}, 3000, "easeInOutBack");
		
		// determine total width
		$('.gallery').data('totalWidth', 0);
		$('.gallery img').each(function() {
			$('.gallery').data('totalWidth', parseInt(parseInt($('.gallery').data('totalWidth')) + $(this).outerWidth()));
		})
		
		// add next and prev buttons
		var prev = $('<a href="" class="gallery_prev">prev</a>');
		var next = $('<a href="" class="gallery_next">next</a>');

		// append nav to gallery, as well as set current item in gallery
		$('.gallery_container')
			.prepend(prev)
			.append(next)
			.data('current', 1);
		
		// set nav hover states
		$('.gallery_prev, .gallery_next').css('opacity', 0.7).hover(
			function() {
				$(this).css('opacity', '0.9');
			},
			function() {
				$(this).css('opacity', '0.7');
			}
		);
		
		// recursive function for moving the gallery to the left
		var moveLeft = function() {
			// if the gallery has moved all the way to the right, then stop it
			if (parseInt($('.gallery').css('left')) >= 0) {
				return false;
			}
			// otherwise animate 3px and then check again
			$('.gallery').animate(
				{"left": '+=3px'},
				3, moveLeft
			)
		}
		
		// recursive function for moving the gallery to the right
		var moveRight = function() {
			// if the gallery has moved all the way to the left, then stop it
			if (Math.abs(parseInt($('.gallery').css('left'))) >= parseInt($('.gallery').data('totalWidth') - $('.gallery_container').outerWidth())) {
				return false;
			}
			// otherwise animate 3px and then check again
			$('.gallery').animate(
				{"left": '-=3px'},
				3, moveRight
			)
		}
		
		// cease to animate whenever the mouse leaves the prev or next buttons
		var cease = function() {
			$('.gallery').stop();
		}
		
		// when you hover move the gallery
		next.mouseenter(moveRight);
		next.mouseleave(cease);
		prev.mouseenter(moveLeft);
		prev.mouseleave(cease);
		
})