$(function()
{
	$.extend($.fn.carousel = function()
	{
		var element = this;
		element.children().each(function(i)
		{
			$(this).css({ display: 'block', position: 'absolute' });
			if($(this).children().length > 0)
			{
				$(this).css('width', $(this).children().width());
				$(this).css('height', $(this).children().height());
			}
		});
		var width = element.children(':first').width();
		var height = element.children(':first').height();
		var top = element.height();
		var left = element.width();
		element.extend($.fn.setDegrees = function(degrees)
		{
			t = degrees / 360 * 2 * Math.PI;
			posCarsousel(this, width, height, top, left, t);
		});
		element.setDegrees(0);
	});
	
	function posCarsousel(element, width, height, top, left, degrees)
	{
		element.children().each(function(i)
		{
			j = (i/element.children().length * Math.PI*2) + degrees;
			var x = Math.sin(j);
			var y = Math.cos(j);
			if($(this).children().length > 0)
			{
				$(this).css({ height: height*((y+3)/4), width: width*((y+3)/4), left: left/2 + x*(left/2-width/2) - width/2, top: top/2 + y*(top/2-height/2) - height/2, 'z-index': Math.round(height*((y+3)/4)) });
				$(this).children().css({ height: height*((y+3)/4), width: width*((y+3)/4) });
			}
			else
			{
				$(this).css({ height: height*((y+3)/4), width: width*((y+3)/4), left: left/2 + x*(left/2-width/2) - width/2, top: top/2 + y*(top/2-height/2) - height/2, 'z-index': Math.round(height*((y+3)/4)) });
			}	
		});
	}
});
