package classes.matuto.utils.display
{
	
	
	import flash.display.*;
	import flash.geom.*;

	public class Reflexo extends Sprite
	{
		
		private var 		imagem			:DisplayObject;
		private var 		distancia		:Number;
		private var 		intAtual		:Number;
		private var 		alpha1			:Number;
		private var 		alpha2			:Number;
		private var 		transparent		:Boolean;
		private var 		cor				:uint;
		private var 		porcento		:Number;
		
		private var 		bitMapData		:BitmapData;
		private var 		bitMap			:Bitmap;
		private var 		matrix			:Matrix;
		
		public function Reflexo(
			
								_imagem			:DisplayObject,
								_distancia		:Number=0,
								_intAtual		:Number=0,
								_transparencia	:Boolean=true,
								_alpha1			:Number=.5,
								_alpha2			:Number=0,
								_cor			:uint=0,
								_porcento		:Number=.6
						
							   ):void
			
		{
			
			
			imagem 			= _imagem;
			distancia 		= _distancia;
			intAtual		= _intAtual;
			transparent		= _transparencia;
			alpha1			= _alpha1;
			alpha2			= _alpha2;
			cor				= _cor;
			porcento		= _porcento*255;
			
			createReflex();
			
			return void;
			
		}
		
		private function createReflex():void
		{
			
			bitMapData 		= new BitmapData(imagem.width,imagem.height,transparent,cor);
			
			matrix 	   		= new Matrix();
			
			matrix.scale(imagem.scaleX,imagem.scaleY);
			
			bitMapData.draw(imagem,matrix);	
			
			bitMap 	    	= new Bitmap(bitMapData);
		
			bitMap.scaleY 	= -1;	
			bitMap.y 		= imagem.height;
		
			criaMascara();

		    return void;
		}
		
		private function criaMascara():void
		{
		 
		   var gradType			:String			= GradientType.LINEAR;
		   var gradRot			:Number 		= Math.PI/2;
		   var gradCor			:Array  		= [0,0];
		   var gradAlpha   		:Array  		= [alpha1,alpha2];
		   var gradProp			:Array			= [0,porcento];
		   
		   var mascaraX			:Number			= bitMap.x;
		   var mascaraY			:Number			= bitMap.y - bitMap.height;	
		   var mascaraW			:Number			= bitMap.width;
		   var mascaraH			:Number			= bitMap.height;
			
		   var matrixMascara	:Matrix			= new Matrix();
		   var shape			:Shape			= new Shape();
		   
		   matrixMascara.createGradientBox(mascaraW,mascaraH,gradRot,mascaraX,mascaraY);
		   
		   shape.graphics.beginGradientFill(gradType,gradCor,gradAlpha,gradProp,matrixMascara);
		   shape.graphics.drawRect(mascaraX,mascaraY,mascaraW,mascaraH);
		   shape.graphics.endFill();
		   
		   shape.cacheAsBitmap 		= true;
		   bitMap.cacheAsBitmap 	= true;

		   addChild(bitMap);
		   addChild(shape);
		   
		   bitMap.mask = shape;
		   
		   this.x = imagem.x;
		   this.y = (imagem.y + imagem.height)+distancia;
		   
		   return void;
		}
		
		
	}//end class
}