var user_facebook = new function() {
	var o = this;

	this.connect_accept = function(refresh) {
		$.getJSON('/users/login_script.php', {site: 'facebook'}, function(data) {
			if(data.login && refresh) { // Signing in with FB button not on login page
				FB.ensureInit(function() {
					FB.Connect.forceSessionRefresh(function() {
						document.location.reload();
					});
				});
				return;
			}

			if (data.referrer=="/users/register") {
				register_popup();
			} else {
				document.location.href = data.referrer;
			}
		});
	}

	this.login = function(refresh) {
		Facebook.connect(function() {
			user_facebook.connect_accept(refresh)
		})
	}

	// Maps a logged in user to facebook account.  Assumes the user is logged in
	this.map = function() {
		Facebook.connect(function() {
			$.get('/users/map_sso_user.php', function() {
				document.location.reload();
			})
		})
		return false;
	}	

};

