//facebook-specific functions

function PublishToFeed(headline, description, href, imageUrl)
{
	var attachment = {
		'name' : headline
		,'href' : href
		,'description' : description
		,'media' : [{
			'type' : 'image'
			,'src' : imageUrl
			,'href' : href
		}]
	};
	var action_links = [{
		'text' : 'Play now!'
		,'href': href
	}];

	if(Facebook)
	{
		Facebook.streamPublish('', attachment, action_links);
	}
	return false;
}

function PublishToFeedViaConnect(headline, description, href, imageUrl)
{
	var attachment = {
		'name' : headline
		,'href' : href
		,'description' : description
		,'media' : [{
			'type' : 'image'
			,'src' : imageUrl
			,'href' : href
		}]
	};
	var action_links = [{
		'text' : 'Play now!'
		,'href': href
	}];

	if(FB && FB.Connect)
	{
		FB.Connect.get_status().waitUntilReady(function(status) {
			FB.Connect.streamPublish('', attachment, action_links);
		});
	}
	return false;
}

function CheckExtendedPermissions(callbackFunction)
{
	//callbackFunction will get comma-separated list of permissions on success, '' on failure or dialog cancel
	if(Facebook)
	{
		Facebook.showPermissionDialog('publish_stream', callbackFunction, showProfileSelector, '');
	}
	return false;
}

function BuildProfileSummary(currentElement, id)
{
	if('undefined' == typeof(Ajax))
	{
		//not on facebook, return alternate way
		return true;
	}
	
	var ajax = new Ajax();
	ajax.responseType = Ajax.FBML; //type can be Ajax.JSON, Ajax.FBML, or Ajax.RAW
	ajax.ondone = function(data)
		{
			var dialogTitle = 'Profile';
			var dialogContents = data;
			var dialogConfirmText = 'View full profile';
			var dialogCancelText = 'Close';

			var dialog = new Dialog(Dialog.DIALOG_CONTEXTUAL);
			dialog.setContext(currentElement);
			dialog.showChoice(dialogTitle, dialogContents, dialogConfirmText, dialogCancelText);
			dialog.onconfirm = function()
				{
					document.setLocation(currentElement.getHref());
				}
		}
	ajax.post(cWEB_ROOT + '/fb/expenttest/profile_summary.php?id=' + id);
	return false;
}