 var FbHelper = 
 {
		 APP_ID : null,
		 debug : false,
		 language : 'en_US',
		 perms : null,
		 initFb : function(session,onFbInit)
		 {
	 		var fbHelperInst = this;
	 		window.fbAsyncInit = function()
	 		{
	 			FB.init({
	 		          appId   : fbHelperInst.APP_ID,
	 		          session : session, // don't refetch the session when PHP already has it
	 		          status  : true, // check login status
	 		          cookie  : true, // enable cookies to allow the server to access the session
	 		        });
	 			if(typeof onFbInit == "function")
	 			{
	 				
	 			}
	 		};
	 		var file = "all.js";
	 		var language = this.language
	 		if(this.debug)
	 		{
	 			language=  "en_US";
	 			var file = "core.debug.js";
	 		}
	 		var e = document.createElement('script');
	 		e.src = document.location.protocol + '//connect.facebook.net/'+language+'/'+file;
	 		e.async = true;
	 		$('body').append('<div id="fb-root"></div>');
	 		document.getElementById('fb-root').appendChild(e);
		 },
		 attachLoginEventIfNotLoggedIn : function(onLogin,noCheck)
		 {
			 var fbHelperInst = this;
			 if(typeof onLogin != "function")
			 {
				 onLogin = function()
				 {
					 if(typeof fbHelperInst.loginUrl  == "string")
					 {
						 window.location = fbHelperInst.loginUrl;
					 }else
					 {
						 window.location.reload();
					 }
				 };
			 }
			 var response =  FB.getSession();
			 if(!response || noCheck == true)
			 {
				 FB.Event.subscribe('auth.login', onLogin); 
			 }
		 },
		 login : function(onLogin,perms)
		 {
			 if(!perms)
			 {
				 if(this.perms)
				 {
					 perms = this.perms;
				 }else
				 {
					 perms = "email";
				 }
			 }
			 if(typeof onLogin != "function")
			 {
				 onLogin  = function(){};
			 }
			 FB.login(onLogin,{perms:perms});
		 }
		 
 };
