(function($) {
	$.fn.imageSlider = function(options) {

 		var options = $.extend({}, $.fn.imageSlider.defaults, options);

		return this.each(function() {
			var $this = $(this);
			/* resize image container to fit content */
			var _images = $('> ' + options.imagesDiv, this);
			var _contentWidth = _images.children().last().position().left + _images.children().last().width();
			$(options.imagesDiv).css({'width': _contentWidth+1 });
			/* animate content */
			$this.mousemove(function(e){
				var mouseX = e.pageX - $this.offset().left;
				var _animLeft = Math.round(mouseX / $this.width() * ($this.width()-_contentWidth));
				_images.animate({
					marginLeft: _animLeft
				}, { queue:false, duration:1000}, "easeOutCirc");
			});
			
			/* update caption */
			_images.find('img').hover(function(){
				$(options.captionElement).html($(this).attr('alt'));
			});
 		});
  	};  

	/* defaults */
	$.fn.imageSlider.defaults = {
		imagesDiv: '.images',
		captionElement: '#caption'
	};
})(jQuery);
