package classes.matuto.loaders.youtube
{
	
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.system.Security;

	
	//GS
	import gs.*;
	import caurina.transitions.*;
	import fl.transitions.easing.*;
	import fl.transitions.*;
	import fl.motion.easing.*;
	
	
	public class YouTubePlayer extends MovieClip
	{
		private var alvo:Object;
		private var carrega:Loader;
		
		public  var largura:Number;
		public  var altura:Number;
		
		public function YouTubePlayer() 
		{
		}
		
		public function init(id:String, _largura:int, _altura:int):void 
		{
			
			largura = _largura;
			altura  = _altura;
			
			Security.allowDomain("www.youtube.com");
			
			carrega = new Loader();
			carrega.contentLoaderInfo.addEventListener(Event.INIT, carregaInit);	
			carrega.load(new URLRequest("http://www.youtube.com/v/"+id+"?version=3"));
		
		}
		
		private function carregaInit(e:Event):void {
			
			addChild(carrega);
			carrega.content.addEventListener("onReady", onPlayerReady);
			carrega.content.addEventListener("onError", onPlayerError);
			carrega.content.addEventListener("onStateChange", onPlayerStateChange);
			carrega.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
			
		}
		
		private function onPlayerReady(event:Event):void 
		{
			alvo = carrega.content;
			alvo.setSize(largura,altura);
         }
		 
		 
		 public function close()
		 {
			 
			 
			alvo.pauseVideo();
			carrega.unload();
			alvo = null;
			 
		 }

		private function onPlayerError(event:Event):void
		{
		}

		private	function onPlayerStateChange(event:Event):void
		{
				
				
		}

		private function onVideoPlaybackQualityChange(event:Event):void 
		{
				
				
        }
		
		/*
		 *  MODO DE USO
		 *  video = new YouTubePlayer();
			video.init("_No3PuIiJ4Q", 400, 200);
			addChild(video);
		 * 
		 * */
		
		 
		
		
		
	
		
	}//END CLASS

}