// VERSION: 1.0 LAST UPDATE: 19.03.2011
/* 
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 * 
 * Made by Tommy Thierry, tommy.thierry@gmail.com, Montreal, QC
 * Website: http://www.tom-art.ca/
 */
(function($) {	
	// Fonction Rotation
    $.fn.rotation = function(options) 
	{
		var X =  $('body').width()/2 - 50;
		var Y =  $('body').height()/2 - 50; 
		//alert(X + ' ' + Y);
		var defaults = {
			XCenter : X,			
			YCenter : Y,
			radius : 200,
			angle : 0,
			direction : 'right',		
			speed : 50,
			change : 0.1,			
			zIndex : 1
		};
			
		var opts = $.extend(defaults, options); 
		$(this).css('position', 'absolute');
		$(this).css('z-index', opts.zIndex);		
		
		var MoveX = parseInt((opts.radius * Math.cos(opts.angle)) + opts.XCenter);
   		var MoveY = parseInt((opts.radius * Math.sin(opts.angle)) + opts.YCenter);
		//alert('MoveX: ' + MoveX + '\n' + 'MoveY: ' + MoveY + '\n');
		$(this).css('top', MoveY);
		$(this).css('left', MoveX);
		
		
		function move(object)
		{
			if(opts.direction != 'right') opts.angle -= opts.change;
			else opts.angle += opts.change;
			//alert(opts.angle);
			MoveX = parseInt((opts.radius * Math.cos(opts.angle)) + opts.XCenter);
   			MoveY = parseInt((opts.radius * Math.sin(opts.angle)) + opts.YCenter);
			//alert(defaultPoint);
			//alert('MoveX: ' + MoveX + '\n' + 'MoveY: ' + MoveY + '\n');
			$(object).animate({
					left: MoveX,
					top: MoveY
				}, opts.speed, function() {
					move(object);
				}
			);
		}
		
		move(this);
	};
})(jQuery);
