package classes.matuto.mov
{
	
	
	
	import classes.greensock.*;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.*;

	public class Rotation extends Sprite
	{
		private static var estagio		:Stage;
		private static var obj			:DisplayObject;
		private static var alvo			:Sprite;
		private static var type 		:String;
		
		private static var nivelX 		:Number;
		private static var nivelY 		:Number;
		
	
		public function Rotation() 
		{
		
		
		}
		
		public static function init(_stage:Stage,_obj:DisplayObject,_alvo:Sprite,_type:String = "x",_nivelXY:Object=null):void
		{
			
			obj 	= _obj;
			alvo    = _alvo;
			estagio = _stage;
			
			type    = _type;
									
			alvo.addChild(obj);
		
			obj.x = -(obj.width  >> 1);
			obj.y = -(obj.height >> 1);
			
			if (_nivelXY == null)
			{
			   nivelX = 45;	
			   nivelY = 45;	
			   
			}else {
			  
			   nivelX = _nivelXY.x;
			   nivelY = _nivelXY.y;
				
			}
					
			estagio.addEventListener(MouseEvent.MOUSE_MOVE, moveCamera);
		
		}
		
		private static function moveCamera(param1:MouseEvent) : void
        {
			
            var _loc_2:Number;
            var _loc_3:Number;
            var _loc_4:Number;
			
            _loc_2 = (param1.stageX - estagio.stageWidth / 2) /  (estagio.stageWidth / 2);
            _loc_4 = (param1.stageX - estagio.stageWidth / 2) /  (estagio.stageWidth / 4);
            _loc_3 = (param1.stageY - estagio.stageHeight / 2) / (estagio.stageHeight / 2);
			
            TweenLite.killTweensOf(obj);
			
			if (type == "x")
			{
				
			   TweenLite.to(alvo, 1, { rotationY:(nivelY * _loc_2) } );
			   
			}else
			{
				
			   TweenLite.to(alvo, 1, { rotationY:(nivelX * _loc_2), rotationX:(nivelY * _loc_3) } );
			   
			}
			
			param1.updateAfterEvent();
			
            return;
        }
		
	}//END CLASS

}