/**
 * @author Livingstone
 */
//alert('loaded');
 var joom_connect = new function()
 {
 	this.token 		= '';
	this.fbcid 		= '';
	this.callback 	= '';
	this.data 		= '';
	
	this.init = function(){
		//alert('You’re uid =' + FB.Facebook.apiClient.get_session().uid);
	    this.fbcid = FB.Facebook.apiClient.get_session().uid ;
		jQuery.facebox(
			new Ajax('index.php',{
				postBody: Object.toQueryString({
					"cmd" : "Users.auth_facebook_user."+FB.Facebook.apiClient.get_session().uid,
					"json": "uresp",
					"tmpl": "component",
					"format":"raw",
					"option":"com_joomunity"
				}),
				onComplete: function(inResponse)
				{
					//alert(inResponse);
					
					e = Json.evaluate(inResponse);
					
					joom_connect.token = e.uresp.token;
					joom_connect.data  = e.uresp.data;
					
					 eval(e.uresp.callback) ;
				}
			}).request()
		);
	};
	this.confirmUser = function(){
		jQuery.facebox(joom_connect.data.form); 
		//FB.XFBML.ProfilePic($('logindiv'));
	}
	this.joinCommunity = function(){
		jQuery.facebox(
			new Ajax('index.php',{
				postBody: Object.toQueryString({
					"cmd" : "Users.facebook_user_join."+joom_connect.fbcid,
					"json": "uresp",
					"tmpl": "component",
					"format":"raw",
					"option":"com_joomunity",
					"t": joom_connect.token
				}),
				onComplete: function(inResponse)
				{	
					e = Json.evaluate(inResponse);
						
					joom_connect.token = e.uresp.token;
					joom_connect.data  = e.uresp.data;
					
					eval(e.uresp.callback) ;
				}
			}).request()
		);
	};
	this.destroySession = function(){
		
	};
	this.bindUser = function(){
		form = document.getElementById('bindUserForm');
		jQuery.facebox(		
			form.send({
	            onComplete: function(inResponse) 
				{
				   e = Json.evaluate(inResponse);
				   
	               joom_connect.token = e.uresp.token;
				   joom_connect.data  = e.uresp.data;
					
				   eval(e.uresp.callback) ;
	            }
	        })
		);
		return false;
	}
	this.showProfile = function(){
		window.location = window.location
	}
	
	this.updateSession = function(){
		//if we found a user in the backend update session
		//move to profile homepage
	};
 }
 
 
 
 
//alert('loaded');