package modules.home  
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import classes.matuto.model.Model;
	import classes.matuto.loaders.*;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import genericos.*;
	import flash.net.*;
	import modules.noticias.Noticias;
		//Matuto
	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 modules.noticias.*;
	import modules.siglario.*;
	import modules.kit.*;
	import modules.agendamento.*;
	import modules.contato.*;
	import modules.tabela.*;

	/**
	 * ...
	 * @author Gustavo Cosme
	 */
	
	 
	public class Home extends MovieClip 
	{
		
		
		private var image:ImagemLoad;
		private var interna:NoticiasInterna
		private var list:XMLList;
		public var botoes:Array = [];
		public var atual:MenuBotao;
		
		public function Home() 
		{
			super();
			
			
			alpha = 0;
			_c._topo.alpha = 0;
			
			addEventListener(Event.ADDED_TO_STAGE, add);
			addEventListener(Event.REMOVED_FROM_STAGE, remove);
		}
		
		private function remove(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, remove);
		}
		
		private function add(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, add);

			x = 300;
			TweenMax.to(this,.6,{x:0,autoAlpha:1,ease:Exponential.easeInOut,onComplete:function(){
			}});			
			initMenu();
			initNoticia();
			
			
		}
		
		private function initNoticia():void 
		{
			Model.XML_CONNECT("http://gfv.com.br/santajoana/portalmedico/noticias.xml",onCompleteXml);
		}
		
		
		private function onCompleteXml(e:XML)
		{
		
			list = e.data;
			//trace(list[0].title);
			//trace(list[0].date);
			//trace(list[0].text);
		
			_c._topo._titulo.text = list[0].title;
			_c._topo._data.text = list[0].date;
			
			image = new ImagemLoad();
			image.alvo_mc = _c._topo._foto;
			image.setComAlvo = true;
			image.load(list[0].image);
			
			_c._topo.addEventListener(Event.SELECT, onSelectThumb);
			
			TweenMax.to(_c._topo, 1.5, { autoAlpha:1, ease:Exponential.easeInOut } );			
		}
		
		private function onSelectThumb(e:Event):void 
		{
		
		   TweenMax.to(_c,.5,{x:-200,autoAlpha:0,ease:Exponential.easeInOut,onComplete:function(){}});
		   NoticiasInterna.MODEL = list[0];
		   interna = new NoticiasInterna();
		   interna.addEventListener(Event.CLOSE, onCloseInterna);
		   addChild(interna);
		  
		}
		
		private function onCloseInterna(e:Event):void 
		{
			TweenMax.to(_c,.5,{x:10,autoAlpha:1,ease:Exponential.easeInOut,onComplete:function(){}});
			
		}
		
		
		private function initMenu():void 
		{
			
			_c._noticias.fragment = Noticias;
			_c._solicitacao.fragment = Agendamento;
			_c._siglario.fragment = Siglario;
			_c._tabelas.fragment = Tabela;
			_c._kit.fragment = Kit;
			_c._fale.fragment = Contato;
			
			botoes = [_c._noticias,_c._solicitacao,_c._siglario,_c._tabelas,_c._fale,_c._kit];
			
			_c._solicitacao.bgColor = 0xFFFFFF;
			_c._solicitacao.textoColor = 0x0277d1;
			_c._solicitacao.iconColor = 0x0277d1;
			
			_c._siglario.bgColor = 0xFFFFFF;
			_c._siglario.textoColor = 0x0277d1;
			_c._siglario.iconColor = 0x0277d1;
			
			_c._tabelas.bgColor = 0xFFFFFF;
			_c._tabelas.textoColor = 0x0277d1;
			_c._tabelas.iconColor = 0x0277d1;
		
			_c._fale.bgColor = 0xFFFFFF;
			_c._fale.textoColor = 0x0277d1;
			_c._fale.iconColor =0x0277d1;
			
			_c._kit.bgColor = 0xFFFFFF;
			_c._kit.textoColor = 0x0277d1;
			_c._kit.iconColor = 0x0277d1;
			
			_c._noticias.bgColor = 0xFFFFFF;
			_c._noticias.textoColor = 0x79b643;
			_c._noticias.iconColor =0x79b643;
			
			_c._logout.bgColor = 0xFFFFFF;
			_c._logout.textoColor = 0x0277d1;
			_c._logout.iconColor = 0x0277d1;
			
			for each(var b:MenuBotao in botoes )
			{
				b.addEventListener(MouseEvent.CLICK, onCLickBotao);
			}
			
			_c._logout.addEventListener(MouseEvent.CLICK, onCLickSair);

			
			
		}
		
		private function onCLickSair(e:MouseEvent):void 
		{
			var call:Object = new Object();
			call.call = function() {
			
				
				var model:ModelApp = new ModelApp();
				model.SAVE_LOCAL("login","");


				
			};
			
			Menu.INSTANCE.DIALOG_SIM_NAO("Gostaria de sair?", call);
		}
		
		private function onCLickBotao(e:MouseEvent):void 
		{
			var name:String = e.currentTarget.name;
			Menu.INSTANCE.slide.updateButton(name.replace("_",""));
			Menu.INSTANCE.initFragment(new e.currentTarget.fragment());
		}
		
	}//END CLASS

}