function fb_save_id_and_refresh()
{
	var fb_id = FB.Connect.get_loggedInUser();

	new Ajax.Request
	(
		"/facebook_connect/fb_connect.php",
		{
			method     : 'post',
			parameters : { action : 'set_facebook_id', fb_id : fb_id },
			onSuccess  : function(transport) { location.href = location.href; }
		}
	);
}

function post_connect_redirect()
{
	var fb_id = FB.Connect.get_loggedInUser();

	new Ajax.Request
	(
		"/facebook_connect/actions/post_connect_redirect.php",
		{
			method     : 'post',
			parameters : { fb_id : fb_id },
			onSuccess  : function(transport) { location.href = location.href; }
		}
	);
}

function fb_make_wall_post(publish_callback)
{
	FB.ensureInit
	(
		function()
		{
			var media = 
			[
				{
					'type' : 'image',
					'href' : 'http://www.fitbrains.com',
					'src'  : 'http://beta.fitbrains.com/i/icons/Fit_Brains_Top_10_Badge.png'
				}
			];

			var attachment =
			{
				'name'        : 'Fitbrains.com',
				'href'        : 'http://www.fitbrains.com',
				'caption'     : '{*actor*} has reached the TOP 10 today playing a brain game at Fitbrains.com!', // 'on the brain game <Wild Word Garden>!',
				'media'       : media,
				'description' : 'Play over 25 fun and free brain games at FitBrains.com'
			};

			FB.Connect.streamPublish
			(
				'', // user_message
				attachment, // attachment
				null, // action_link
				null, // target_id
				"Tell your friends", // user_message_prompt
				publish_callback, // callback
				false, // auto-publish
				null // actor_id (for publishing as a page)
			);
		}
	);
}
