/**
* Get FaceBook session
*/
if(typeof fbSession != 'function')
{
	function fbSession(obj, root_path)
	{
		var url = "", redirect = "";
		root_path = root_path || "";

		while (obj.parentNode)
		{
			obj = obj.parentNode;
			if (obj.tagName.toLowerCase() == 'form')
			{
				if (obj.redirect)
				{
					redirect = obj.redirect.value;
				}
				else if (obj.action)
				{
					var query_str = obj.action.replace(/^.*\?/, '');
					var query_vars = query_str.split('&');
					for (var j=0; j<query_vars.length && !redirect; j++)
					{
						var query_val = query_vars[j].split('=', 2)
						if (query_val[0] && query_val[0] == 'redirect')
						{
							redirect = query_val[1];
						}
					}
				}
				break;
			}
		}
		url = root_path + 'fbconnect.php' + (redirect ? '?redir=' + escape(redirect) : '');
		FB.ensureInit(function()
		{
			FB.Connect.ifUserConnected(url, function ()
			{
				FB.Connect.requireSession(function ()
				{
					document.location = url;
				});
			});
		});
	}
}