/**
*	basically moving the facebook asyncronous loader
*	to our	dynamic script loader architecture.
*	and remove it from the source of the page.
*
*/

var FB; // intialize the scope.
function FacebookLoader(settings){this.settings=settings};
FacebookLoader.prototype =
{
	callback:function(data)
	{
		 document.getElementById('fb-root').appendChild(data);

		
		window.fbSettings=this.settings;
		window.fbAsyncInit = function() 
	    {
	    	
	     	 FB.init({appId: this.fbSettings.appid, status: true, cookie: true, xfbml: true});
	
	          ////////////////////////////////////////////
	          // redefine faulty postTarget method
	          // http://github.com/facebook/connect-js/issues/#issue/65
	          // http://bugs.developers.facebook.com/show_bug.cgi?id=10180
	          ////////////////////////////////////////////
	          origPostTarget = FB.Content.postTarget;
	          FB.Content.postTarget = function(opts) {
	             FB.Array.forEach(opts.params, function(val, key) {
	                if (typeof val == "object" || typeof val == "array") {
	                   opts.params[key] = FB.JSON.stringify(val);
	                }
	             });
	             origPostTarget(opts);
	          };
	          ////////////////////////////////////////////
	
	          FB.getLoginStatus(function(response) {            	 
	 	         if (response.session) {            	 
	                // logged in and connected user, someone you know
	                // good place for callback hooks                    
	             }            	
	      });
	   };
		
		konsole.log('facebook loaded',data);
	},
	load:function()
	{
		try
		{
		
	   
	   
		   Goby.get("scriptLoader").importFile("http://connect.facebook.net/en_US/all.js",{remote:true,async:true,callback:
		   {
		   	object:this,
		   	method:'callback'
		   }});
		
		}
		catch(e)
		{
			konsole.log(e);
		}
	}
}
