/*******************************************************************************
*	jQuery reel carousel plugin
*	Author: Phillip j Parr - http://wizpip.com
*******************************************************************************/

(function($){
		  
	$.fn.extend({
				
		reelCarousel: function(options) {
			
			var defaults = {
				speed: 1,			// angle in degrees we rotate on each iteration
				radiusY: 154,		// how high we want the oval to be
				originY: 100,		// y origin
				originX: 13,		// x origin
				imageWidth: 220,	// largest image size
				smoothness: 50		// smaller is better but more processor intensive
			}
			
			var options = $.extend(defaults, options);			
			var rotation = 0;
		
			return this.each(function() {
				rotateCarousel($(this));
			});
			
			
			function rotateCarousel(obj) {
				var o = options;
				var number = obj.find('li').length;
				var distance = 360 / number; // degrees between each panel
				var start = rotation;
				obj.find('li').each(function() {
					var width = Math.round((Math.cos(start * (Math.PI / 180)) + 1) * o.imageWidth / 2);
					$(this).find('img').css({width: width});
					var height = $(this).find('img').height();
					$(this).css({top: Math.sin(start * (Math.PI / 180)) * o.radiusY + o.radiusY - height / 2 + o.originY, left: o.imageWidth - width / 2 - o.imageWidth / 2 + o.originX, zIndex: width, opacity: width / o.imageWidth});
					start += distance;
					if(start > 360) start -= 360;
				});
				rotation += o.speed;
				if(rotation > 360) rotation -= 360;
				setTimeout(function() { rotateCarousel(obj); }, o.smoothness);
			}
		}
	});
})(jQuery);