package classes.matuto.social.facebook
{
	import classes.adobe.serialization.json.JSON;
	import classes.matuto.core.Matuto;
	import classes.matuto.core.module.Module;
	import classes.matuto.loaders.PHPLoad;
	import classes.matuto.model.Model;
	
	import flash.net.URLVariables;
	
	public class ModuleBaseFacebook extends Module
	{
		
		
		public function ModuleBaseFacebook(localHost:Boolean=false)
		{
			Facebook.getInstance().local = localHost
		}
		
		public override function init():void
		{	
			if(!Facebook.getInstance().local)
				Facebook.getInstance().INICIALIZE(onComplete);
			else
			{
				Facebook.getInstance().INICIALIZE(onComplete,true);
			}
		}
		
		private function onComplete():void
		{
			Facebook.getInstance().getRedirect;	
			Facebook.getInstance().getStatus.toString();	
			Facebook.getInstance().getId;
			
			onPermissionInit();
			
			if(Facebook.getInstance().getStatus==true)
			{
				onPermissionTrue();	
				
			}else
			{
				onPermissionFalse();		 
			}
			
		}
		
		
		public function load():void
		{
			//var urlVar:URLVariables	= new URLVariables();
			//urlVar.funcao		    	= "init";
			
			/*
			
			PHPLoad.getInstance(Matuto.getConfig.getServer+Facebook.getInstance().urlFace,urlVar,function(e:Object):void
			{
			Facebook.getInstance().dadosFriends					= JSON.decode(e.getFriends.toString()) as Array;
			
			Facebook.getInstance().dadosProfile					= JSON.decode(e.getProfile.toString()) as Object;
			onCompletePermissionTrue();
			
			});
			
			*/
			
			Model.XML_CONNECT("visao/xml/facebook/"+Facebook.getInstance().getId+".xml",function(e:XML):void{
				
				Facebook.getInstance().dadosFriends	 	 =  e.amigos.dado;
				onCompletePermissionTrue();
				
			});
			
		}
		
		public function onCompletePermissionTrue():void
		{
			
			
		}
		
		
		
		public function onPermissionInit():void
		{
			
		}
		
		public function onPermissionTrue():void
		{
			
		}
		
		public function onPermissionFalse():void
		{
			
		}
		
		
		
		
	}//end class
}