package classes.gustavo.midia.camera 
{
	import classes.fl.motion.easing.Exponential;
	import classes.greensock.*;
	import classes.matuto.core.Button;
	import classes.matuto.interfaces.*;
	import classes.matuto.utils.display.*;
	
	import flash.display.*;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.media.*;
	
	//import modules.foto.CordelNizeme;
	
	public class CameraG extends MovieClip 
	{
		
		private var camera				:Camera;
		private var video				:Video;
		
		private var bg					:Sprite;
		
		private var foto				:Bitmap;
		public  var fotoFinal			:Bitmap;
		
		private var largura				:Number;
		private var altura				:Number;
		private var color				:uint;
		
		private var estaComFoto			:Boolean = false;
		
		//private var efeito				:CordelNizeme;
	
		
		
	
		public function CameraG() 
		{
			super();
			
			bg 			   = _bg;
			
			largura	       = bg.width;
			altura		   = bg.height;
		}
		
		public function init():void
		{
			if(Camera.getCamera())
			{
				initCamera();
			}
		}
		
		//###############################################################//
		//CAMERA
		//###############################################################//
		
		private function initCamera():void 
		{
			camera 		= Camera.getCamera();
			camera.setMode(largura,altura,30);
			video 		= new Video(largura+2,altura+1);
			video.attachCamera(camera);
			video.scaleX  = -1
			video.x = 4.3+largura;
			video.y = 2.15;
			addChildAt(video,3);	
		}
		
		//###############################################################//
		//###############################################################//

		//###############################################################//
		//PHOTO
		//###############################################################//
		
		public function tiraFoto():void
		{

			estaComFoto    = true;			
			foto 		   = DisplayObjectUtils.PhotoDisplayCopy(video,new Rectangle(0,0,_bg.width+1,_bg.height+1));
			foto.scaleX    = -1
			foto.x 		   = 4.3+largura;
			foto.y		   = 2.15;
			foto.blendMode = BlendMode.MULTIPLY;
			addChildAt(foto,3);
			TweenMax.to(foto, 1, {ease:Exponential.easeInOut,"colorMatrixFilter":{"colorize":0, "amount":.2, "brightness":1, "threshold":60}});
			removeChild(video);
		}
		
		public function tiraFotoFinal():void
		{
			estaComFoto    = true;			
			foto 		   = DisplayObjectUtils.PhotoDisplayCopy(this,new Rectangle(0,0,_bg.width+7,_bg.height+6));
			foto.blendMode = BlendMode.MULTIPLY;
			TweenMax.to(foto,0, {ease:Exponential.easeInOut,"colorMatrixFilter":{"colorize":0, "amount":.2, "brightness":1, "threshold":60}});
			fotoFinal      = DisplayObjectUtils.PhotoDisplayCopy(this,new Rectangle(0,0,_bg.width+8,_bg.height+6));
			addChild(fotoFinal);
		}
		
		public function reset():void
		{
			removeChild(foto);
			foto = null;
			estaComFoto = false;
			addChildAt(video,3);	
		}
		
		public function get getPhoto():Bitmap
		{
			return foto;
		}
	
		//###############################################################//
		//###############################################################//

		
		public function dispose():void 
		{
			removeChild(video);
			removeChild(bg);
			
			if (foto)
			{
			   removeChild(foto);
			   foto = null;
			}
			
			camera = null;
			video  = null;
			bg     = null;
		}
		
	
		
		
	}//end class

}