/*
* jQuery-1.4.4 carousel by FirstView (http://firstviewmedia.com).
* This lets you 
* Options include 
*/
/*
Eg. :


*/

(function($){
	$.fn.carousel = function(opts) {
	
		var defaults = {
			carousel: '.carouselWrapper'		// The selector to slide. //
		};
		var opts								= $.extend(defaults, opts);
		
		return this.each(function(){
			
			var $this							= $(this);
			var $carousel						= $this.find(opts.carousel);
			var initialLeftPos					= Number($carousel.css('left').replace('px', ''));
			var newCarouselWidth				= 0;
			$carousel.children().each(function(){
				if( $(this).css('position') != 'absolute' && $(this).css('position') != 'fixed' ){
					newCarouselWidth += $(this).outerWidth();
				}
			});
			$carousel.width(initialLeftPos+newCarouselWidth);
			var maxLeft							= $carousel.width()-$this.width();
			var extraSpace						= maxLeft*.1;
			var max								= $this.width() - extraSpace;
			
			$this.mousemove(function( e ){
				var handicap = $this.offset().left;
				var perc = (e.pageX-handicap)/max;
				slideCarousel( perc, false);
			});
			
			function slideCarousel( perc, animate){
				var newLeft = extraSpace + initialLeftPos - maxLeft * perc;
				if( animate ) $carousel.animate({'left':newLeft}, {duration:500, easing:'easeInOutQuad'});
				else $carousel.css({'left':newLeft});
			}
			
			// Get ball rolling. //
			slideCarousel( 0, false);
			
			return this;
		});
	};
})(jQuery);

