package modules.menu
{
	
	import classes.greensock.plugins.*;
	import classes.matutoDesktop.view.BaseView;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import genericos.dialogs.Ok;
	import genericos.dialogs.SimNao;
	import genericos.dialogs.Simples;
	import genericos.ModelApp;
	import modules.home.Home;
	import modules.noticias.Noticias;
	import modules.start.Start;
	
	import flash.events.MouseEvent;
	import classes.fl.motion.easing.*;
	import classes.greensock.*;
	import classes.matuto.core.*;
	import classes.matuto.core.module.*;
	import classes.matuto.events.*;
	import classes.matuto.interfaces.*;
	import classes.matuto.model.*;
	import classes.matuto.mtween.textinho.*;
	import classes.matuto.ui.*;
	import classes.matuto.utils.display.*;
	import classes.matuto.utils.model.*;	
	import modules.home.*;
	import modules.menu.*;
	import flash.geom.*;	
	import flash.utils.*;
	import modules.login.*;
	import genericos.dialogs.FormDialog;

	public class Menu extends BaseView 
	{
		
		private var model:ModelApp;
		private var container:MovieClip; 
		private var fragment:MovieClip;
		public static var INSTANCE:Menu; 
		public var slide:MenuSlide;
		
		public var ok:Ok;
		public var simples:Simples;
		public var simOuNao:SimNao;
		public var formOk:FormDialog;
		public var formErro:FormDialog;
		
		
		public function Menu() 
		{
			super();
		}
		
		public function init():void 
		{
			INSTANCE    = this;
			container   = _container;
			width  		= Main.INSTANCE.stage.stageWidth;
			height      = Main.INSTANCE.stage.stageHeight;
			slide       = _slide;
			
			slide.topo = _topo;
			slide.init();
			
			_topo.alpha = 0;
			TweenMax.to(_topo,.5,{autoAlpha:1,ease:Exponential.easeInOut,onComplete:function(){}});

			initFragment(new Home());
			
		}
		
		public function initFragment(value:MovieClip)
		{
		
			
			
			if (fragment != null)
			{
				var del:MovieClip = fragment;
				TweenMax.to(del,.4,{x:-200,autoAlpha:0,ease:Exponential.easeInOut,onComplete:function(){
				
					
				}});
				
				
				setTimeout(function() { 
					
				    fragment = value;
					container.addChild(fragment);
			
					
				}, 200);
				
				slide.onCLickClose();

				
			}
			else {
				
				
				
				fragment = value;
				container.addChild(fragment);
			
				slide.onCLickClose();
			
			}
			
		
		}
		
		
		private function onClick(e:MouseEvent):void 
		{

		}
		
		
		public function close():void 
		{
			
		}
		
		public function dispose():void 
		{
			
			
		}
		
		public function resize():void 
		{
			
		}
		
		
		public function DIALOG_OK(value:String)
		{
			_slide.filters = [new BlurFilter(10, 10)];
			_container.filters = [new BlurFilter(10, 10)];
			
			ok = new Ok();
			addChild(ok);
			ok._t.text = value;
			
			ok.addEventListener(Event.CLOSE, function(e:Event) { 
					
				TweenMax.to(ok,.4,{autoAlpha:0,ease:Exponential.easeInOut});

				setTimeout(function() { 
					
					_slide.filters = [new BlurFilter(0, 0)];
					_container.filters = [new BlurFilter(0, 0)];
					removeChild(ok);
					ok = null;
					
				},300);
				
		    });

		}			
		
		public function DIALOG_SIMPLES(value:String)
		{
			_slide.filters = [new BlurFilter(10, 10)];
			_container.filters = [new BlurFilter(10, 10)];
			
			simples = new Simples();
			addChild(simples);
			simples._t.text = value;
			
			simples.addEventListener(Event.CLOSE, function(e:Event) { 
					
				TweenMax.to(simples,.4,{autoAlpha:0,ease:Exponential.easeInOut});

				setTimeout(function() { 
					
					_slide.filters = [new BlurFilter(0, 0)];
					_container.filters = [new BlurFilter(0, 0)];
					removeChild(simples);
					simples = null;
					
				},300);
				
		    });

		}		
		
		
		public function DIALOG_SIM_NAO(value:String,call:Object)
		{
			_slide.filters = [new BlurFilter(10, 10)];
			_container.filters = [new BlurFilter(10, 10)];
			

			simOuNao = new SimNao();
			addChild(simOuNao);
			simOuNao._t.text = value;

			simOuNao.addEventListener(Event.CLOSE, function(e:Event) { 
					
				TweenMax.to(simOuNao,.4,{autoAlpha:0,ease:Exponential.easeInOut});

				setTimeout(function() { 
					
					_slide.filters = [new BlurFilter(0, 0)];
					_container.filters = [new BlurFilter(0, 0)];
					removeChild(simOuNao);
					simOuNao = null;
					
				},300);
				
		    });			
			
			simOuNao.addEventListener(Event.SELECT, function(e:Event) { 
					
				TweenMax.to(simOuNao,.4,{autoAlpha:0,ease:Exponential.easeInOut});

				setTimeout(function() { 
					
					
					call.call();
					_slide.filters = [new BlurFilter(0, 0)];
					_container.filters = [new BlurFilter(0, 0)];
					removeChild(simOuNao);
					simOuNao = null;
					
					Main.INSTANCE.core.updateLocal(new Login());
					
				},300);
				
		    });

		}
		
		
		public function DIALOG_OK_FORM()
		{
			_slide.filters = [new BlurFilter(10, 10)];
			_container.filters = [new BlurFilter(10, 10)];
			
			formOk = new DialogOkForm();
			addChild(formOk);
			
			formOk.addEventListener(Event.CLOSE, function(e:Event) { 
					
				TweenMax.to(formOk,.4,{autoAlpha:0,ease:Exponential.easeInOut});

				setTimeout(function() { 
					
					_slide.filters = [new BlurFilter(0, 0)];
					_container.filters = [new BlurFilter(0, 0)];
					removeChild(formOk);
					formOk = null;
					
				},300);
				
		    });

		}		
		
		public function DIALOG_ERRO_FORM()
		{
			_slide.filters = [new BlurFilter(10, 10)];
			_container.filters = [new BlurFilter(10, 10)];
			
			formErro = new DialogErroForm();
			addChild(formErro);
			
			formErro.addEventListener(Event.CLOSE, function(e:Event) { 
					
				TweenMax.to(formErro,.4,{autoAlpha:0,ease:Exponential.easeInOut});

				setTimeout(function() { 
					
					_slide.filters = [new BlurFilter(0, 0)];
					_container.filters = [new BlurFilter(0, 0)];
					removeChild(formErro);
					formErro = null;
					
				},300);
				
		    });

		}
		
		
	}//END CLASS

}