/**
 * nbkf_support.js
 *
 *	Must be included
 */

//********************************************************************************
//* Initialize our variables
//********************************************************************************

//	Handle the query string...
var arScripts = document.getElementsByTagName( 'script' );
var oMyScript = arScripts[ arScripts.length - 1 ];
var arParms = parseQuery( oMyScript.src.replace(/^[^\?]+\??/,'') );
var g_sApiKey = "5b212bbb100acae50ed738c95d8bed7a";

//	Pull out our constants
var g_iTemplateId = arParms[ 'tid' ];
var g_sCallbackUrl = arParms['cburl'];
var g_sInviteResponseUrl = arParms['irurl'];
var g_sBaseUrl = arParms[ 'burl' ];
var g_sAppUrl = 'http://apps.facebook.com/katamari/?published&section=canvas_temp'
var g_sProfileAID = null;
var g_arProfilePhotoXml = null;
var g_sFirstName;
var	g_sPFUserId;

//******************************************************************************************
//* Back-end API Functionality
//******************************************************************************************

function makeAjaxRequest( arData, fnCallback )
{
	var sName = arData.c;
	
	$.post( g_sBaseUrl, arData, 
		function( arResponseData, sResponseStatus ) { 
			if ( fnCallback == 'NOCALLBACK' ) 
				return;
			
			if ( typeof( fnCallback ) == 'function' ) 
				g_cbTestAjax( sName, arResponseData, sResponseStatus ); 
			else 
				g_cbAjax( sName, arResponseData, sResponseStatus );
		}
	);
}

//	Set up our callbacks...
var g_cbAjax = function( callName, respData, respStatus ) 
{
	var arData = $sNewRank = null;
	sendToActionScript( callName, respData, respStatus );
	statusMsg( "Ajax call " + callName + " has completed with the following status '" + respStatus + "'" );
	
	switch ( callName )
	{
		case 'createUser':
			arData = xml2json.parser(respData);
			if ( arData.results.fb_response == 1 ) 
			{
				FB.Connect.showPermissionDialog( "email, publish_stream", function()
				{
					statusMsg( 'sending email ajax request' );
				    makeAjaxRequest({c:"sendEmail",a1:arData.results.user_uid,a2:arData.results.mail_subject,a3:arData.results.mail_body}, 'NOCALLBACK' );
					statusMsg( 'publish create user story' );
		            window.setTimeout( 'publishStory()', 250 );
				}, true, null );
			}
			break;
		
		case 'acceptInvitation':
			arData = xml2json.parser(respData);
			statusMsg( 'accept invite fbier='+arData.results.inviter_fbid+',fbiee='+arData.results.invitee_fbid);
			if ( arData.results.inviter_fbid && arData.results.invitee_fbid ) 
			{
				var sInviter = arData.results.inviter_fbid;
				var sInvitee = arData.results.invitee_fbid;
				
				if ( sInviter.length > 0 && sInviter !== '' && sInvitee.length > 0 && sInvitee !== '' )
				{
					FB.Connect.showPermissionDialog( "publish_stream", function() 
				    {
				        $sNewRank = null;
				        
				        if ( arData.results.ballSize == 6 )
				        {
		            		$sNewRank = "Uncle Murray";
						}
				        else if ( arData.results.ballSize == 11 )
				        {
		            		$sNewRank = "Friend of Cousin";
						}
				        else if ( arData.results.ballSize == 21 )
				        {
		            		$sNewRank = "Second Cousin";
						}
				        else if ( arData.results.ballSize == 31 )
				        {
		            		$sNewRank = "First Cousin";
						}
				        else if ( arData.results.ballSize == 41 )
				        {
		            		$sNewRank = "Prince's Younger Brother";
						}
				        else if ( arData.results.ballSize == 51 )
				        {
		            		$sNewRank = "THE Prince";
						}
				        else if ( arData.results.ballSize == 61 )
				        {
		            		$sNewRank = "Robo King";
						}
				        else if ( arData.results.ballSize == 81 )
				        {
		            		$sNewRank = "Queen of the Cosmos";
						}
				        else if ( arData.results.ballSize == 101 )
				        {
		            		$sNewRank = "King of the Cosmos";
						}
				        
				        publishStory( ( $sNewRank ? 2 : 1 ), sInviter, sInvitee, $sNewRank, arData.results.ballSize, arData.results.message );
					}, true, null );
				}
		    }
			break;
	}
	
	//	Push focus to flash...
	$('#obj_flash').focus();
};

var g_cbTestAjax = function( callName, respData, respStatus ) 
{
	if ( typeof( respData ) != 'string' ) respData = JSON.stringify( respData );
	var sOut = '<div class="test_status">Call status was ' + respStatus + '</div><br />Results:<div class="test_results">' + respData + '</div>';
	$('#test_' + callName + '_results').html( sOut );
	statusMsg( "Ajax call " + callName + " has completed with the following status '" + respStatus + "'" );
};

/**
* Retrieves the requested user from the database
*
* @param int iUserUID
* @returns array
* @see saveUser
*/
function getUser( iUserUID, fnCallback )
{
	makeAjaxRequest( { c: 'getUser', a1: iUserUID }, fnCallback );
}

function getCachedPhotos( fnCallback )
{
	var sName = 'getCachedPhotos';
	var arData = g_arProfilePhotoXml;
	var sStatus = 'success';

	if ( fnCallback == 'NOCALLBACK' ) 
		return;
		
	if ( typeof( fnCallback ) == 'function' ) 
		g_cbTestAjax( sName, arData, sStatus ); 
	else 
		g_cbAjax( sName, arData, sStatus ); 
}

/**
* Retrieves the requested user from the database
*
* @param string sUserName
* @param string sPassword
* @returns array
* @see getUser
*/
function loginUser( sUserName, sPassword, fnCallback )
{
	makeAjaxRequest( { c: 'loginUser', a1: sUserName, a2: sPassword }, fnCallback );
}

/**
* Creates, updates, saves the requested user
*
* @param int iUserUID
* @param array arData
* @returns bool
* @see getUser
*/
function saveUser( iUserUID, arData, fnCallback )
{
	if ( typeof( arData ) != 'string' ) arData = JSON.stringify( arData );
	makeAjaxRequest( { c: 'saveUser', a1: iUserUID, a2: arData }, fnCallback );
}

/**
* Creates user
*
* @param array arData
* @returns array
* @see getUser
* @see saveUser
*/
function createUser( arData, fnCallback )
{
	if ( typeof( arData ) != 'string' ) arData = JSON.stringify( arData );
	makeAjaxRequest( { c: 'createUser', a1: arData }, fnCallback );
}

/**
* Retrieves a ball from the database
*
* @param int iBallUID
*
* @returns array
* @see saveBall
*/
function getBall( iBallUID, fnCallback )
{
	makeAjaxRequest( { c: 'getBall', a1: iBallUID }, fnCallback );
}

/**
* Retrieves ball rank
*
* @param int iUserUID
*
* @returns string
* @see getBall
*/
function getBallRank( iUserUID, fnCallback )
{
	makeAjaxRequest( { c: 'getBallRank', a1: iUserUID }, fnCallback );
}

/**
* Retrieves the top bals from the database based on score
*
* @param int iHowMany How many to return, limited to 100
*
* @returns array
* @see getBall
*/
function getBallList( iHowMany, fnCallback )
{
	makeAjaxRequest( { c: 'getBallList', a1: iHowMany }, fnCallback );
}

/**
* Saves a ball to the database
*
* @param int iUserUID
* @param array arBall
* @param array arChallenge
*
* @returns bool
* @see getBall
*/
function saveBall( iUserUID, arData, arInvites, fnCallback )
{
	if ( typeof( arData ) != 'string' ) arData = JSON.stringify( arData );
	if ( typeof( arInvites ) != 'string' ) arData = JSON.stringify( arInvites );
	makeAjaxRequest( { c: 'saveBall', a1: arData, a2: arInvites }, fnCallback );
}

/**
* Publishes the results to Facebook
*
* @param arResults
*
* @return bool
*/
function publishResults( arData, fnCallback )
{
	if ( typeof( arData ) != 'string' ) arData = JSON.stringify( arData );
	makeAjaxRequest( { c: 'publishResults', a1: arData }, fnCallback );
}

function checkFBPerms()
{
	$('#obj_flash').focus();
	//	No longer used...
	return;
}

function getInvites( iUserUID, fnCallback )
{
	makeAjaxRequest( { c: 'getInvites', a1: iUserUID }, fnCallback );
}

/**
* Adds an invitation
*
* @param iUserUID
* @param sTargetUserUID 
* @param sSemail
* @param sFBId
*/
function addInvitation( iUserUID, sTargetUserUID, sEmail, sFBId, fnCallback )
{
	arData = JSON.stringify( { target_user_uid: sTargetUserUID, email_addr_text: sEmail, pform_user_id_text: sFBId } );
	makeAjaxRequest( { c: 'addInvitation', a1: iUserUID, a2: arData }, fnCallback );
}

/**
* Accepts an invitation
* 
* @param sInviteCode
*/
function acceptInvitation( sInviteCode, sUserName, sMessage, fnCallback )
{
	makeAjaxRequest( { c: 'acceptInvitation', a1: sInviteCode, a2: sUserName, a3: sMessage }, fnCallback );
}

//******************************************************************************************
//* Facebook Functionality
//******************************************************************************************

function facebook_invite_users( sTitle, sMsg, sRedirUrl )
{
	statusMsg( "facebook_invite_users: called" );
	FB.ensureInit( function()
	{
		facebook_onlogin_ready();
		
		//	Get invited users...
		$.ajax({url:'/NBKFServer.php',async:false,cache:false,data:{c:'getFBInvites',a1:g_sPFUserId},type:'POST', success:function( sData, sResp ) {
			if ( sResp == 'success' ) g_sFBInvites = sData;
		}});
		
		var sAppUrl = g_sInviteResponseUrl + '?fbInvite=&fbi=' + g_sPFUserId;
		var sActionUrl = g_sInviteResponseUrl + '?fbi=' + g_sPFUserId;
		var sChoice = '&lt;fb:req-choice url=&quot;' + sAppUrl + '&quot; label=&quot;Roll Me Up!&quot; /&gt;';
		var sContent = 'Your friend, ' + g_sFirstName + ' would like your help in creating the biggest ball in the Cosmos.  By adding an item to the ball, it grows bigger.  Take a closer look and help ' + g_sFirstName + ' get rolling!               Katamari Forever is available on PS3.     Learn more at: http://www.katamariforever.com';
//		g_sFirstName + ' has created a Katamari ball and wants to roll you up!  Help ' + g_sFirstName + ' create the biggest ball in the Cosmos by accepting the invitation and adding an item to their ball.';
		var sMsg = "The more friends you roll up, the bigger your ball grows.  Users with the biggest ball and the most friends will be eligible for a variety of prizes.";
		
		var sFbml = '<fb:request-form ' 
			+ 'action="' + sActionUrl + '" ' 
			+ 'method="POST" '
			+ 'invite="true" '
			+ 'type="Katamari Forever!" '
			+ 'content="' + sContent + sChoice + '" '
			+ '	<fb:multi-friend-selector '
			+ '		showborder="false" '
			+ '		exclude_ids="' + g_sFBInvites + '" '
			+ '		rows="3" '
			+ '		cols="4" '
			+ '		actiontext="' + sMsg + '" '
			+ '		email_invite="false"'
			+ '/>'
			+ '</fb:request-form>';

		var oDialog = new FB.UI.FBMLPopupDialog( 'Grow your Katamari ball!  Invite your Facebook friends to join your ball.' );
		oDialog.setFBMLContent( sFbml );
		oDialog.setContentWidth( 680 );
		oDialog.setContentHeight( 450 );
		oDialog.show();
		statusMsg( "facebook_invite_users: shown" );
	});
}

/**
* Logs into FBC and checks the connection
*
*/
function loginConnect()
{
	statusMsg( "loginConnect begin" );
	checkConnect();
}

/**
* Logs out of FBC and checks the connection
*/
function logoutConnect()
{
	FB.ensureInit( function()
	{
		FB.Connect.logout( function( bSuccess )
		{
			statusMsg( "Finished logging out!" );
		});
	});
}

/**
* Checks the FBC connection
*
*/
function checkConnect()
{
	statusMsg( "checkConnect begin" );
	FB.ensureInit( function()
	{
		statusMsg( "checkConnect:ensureInit" );
		FB.Connect.requireSession( function( exception ) 
		{
			g_sPFUserId = FB.Facebook.apiClient.get_session().uid;
			json2xml( 'loginConnect', [{pform_user_id_text:g_sPFUserId,status:'success'}] );
		}, true);
	});
}

/**
* A proper FB logout...
*
* Use if users are unable to logout.
*/
function facebookLogout()
{
	FB.ensureInit( function()
	{
		var user = FB.Facebook.apiClient.get_session() ? FB.Facebook.apiClient.get_session().uid : null;
		var singleton = FB.Connect._singleton;
		var nextUrl = FBIntern.Uri.addQueryParameters( FB.XdComm.Server.singleton.get_receiverUrl(), 'fb_login&fname=_parent&session=loggedout' );

		singleton._ensureLoginHandler();
		singleton._logoutCallback = g_sCallbackUrl;

		logoutUrl = FBIntern.Utility.getFacebookUrl( 'www' )
			+ 'logout.php?app_key='
			+ FB.Facebook.apiKey
			+ '&session_key='
			+ encodeURIComponent( FB.Facebook.apiClient.get_session().session_key )
			+ '&next='
			+ encodeURIComponent( nextUrl );

		FB.Facebook.apiClient.set_session( null );
		singleton.set__userInfo( null );
		singleton._logoutIframe = FB.XdComm.Server.singleton.createNamedHiddenIFrame( 'fbLogout', logoutUrl, 'fb_logout', null );
	});
}

/**
* Retrieve user information from FBC
*
*/
function getFBProfile( sPFUserId, fnCallback )
{
	statusMsg( "Loading profile..." + sPFUserId );

	FB.ensureInit(function()
	{
		if ( ! sPFUserId ) sPFUserId = g_sPFUserId;
		
		//	Get the user's info
		FB.Facebook.apiClient.users_getInfo( sPFUserId, 'first_name, last_name, name, pic_square, proxied_email', function( result, ex )
		{
			try
			{
				var arData = result.slice();
				g_sFirstName = arData[0].first_name;
				json2xml( 'getFBProfile', arData, fnCallback );
				
				//	Get album id...
				getFBAlbums( sPFUserId, "NOCALLBACK" );
			}
			catch ( $_ex )
			{
				statusMsg( 'error during getFBProfile: ' + $_ex.description );
				//	Try again.
				facebookLogout();
			}
		});
	});
}

/**
* Retrieve user information from FBC
*
*/
function getFBProfilePhotos( sPFUserId, fnCallback )
{
	if ( ! sPFUserId ) sPFUserId = g_sPFUserId;
	statusMsg( "Loading profile photos for " + sPFUserId );

	FB.ensureInit( function()
	{
		//	Get the user's info
		FB.Facebook.apiClient.photos_get( null, g_sProfileAID, null, function( result, ex )
		{
			$.post( g_sBaseUrl, { c: "json2xml", a1: JSON.stringify( result.slice() ) }, function( arData, sStatus ) 
			{ 
				//	XML returned...
				g_arProfilePhotoXml = arData; 

				if ( fnCallback == 'NOCALLBACK' ) 
					return;
			
				if ( typeof( fnCallback ) == 'function' ) 
					g_cbTestAjax( 'getFBProfilePhotos', arData, sStatus ); 
				else 
					g_cbAjax( 'getFBProfilePhotos', arResponseData, sResponseStatus );
			});
		});
	});
}

/**
* Retrieve photo information from FBC
*
*/
function getFBAlbums( sPFUserId, fnCallback )
{
	if ( ! sPFUserId ) sPFUserId = g_sPFUserId;

	statusMsg( "Loading albums..." + sPFUserId );

	FB.ensureInit( function()
	{
		//	Get the user's info
		FB.Facebook.apiClient.photos_getAlbums( sPFUserId, [], function( result, ex )
		{
			if ( result && $.isArray( result ) ) 
			{ 
				var arData = result.slice();
				
				json2xml( 'getFBAlbums', arData, fnCallback );
				
				g_sProfileAID = arData[0]['aid'];
				statusMsg( 'User Profile Album ID = ' + g_sProfileAID );

				//	Get pictures for cache...
				getFBProfilePhotos( sPFUserId, 'NOCALLBACK' );
			}
			else
			{
				statusMsg( 'getFBAlbums results empty or non-array: ' + result );
				window.setTimeout( 'getFBAlbums()', 1000 );
			}
		});
	});
}

/* Retrieve photo information from FBC
*
*/
function getFBPhotos( sSubjectId, sAlbumId, arPIds, fnCallback )
{
	statusMsg( "Loading photos..." );

	FB.ensureInit( function()
	{
		//	Get the user's info
		FB.Facebook.apiClient.photos_get( sSubjectId, sAlbumId, arPIds, function( result, ex )
		{
			try
			{
				json2xml( 'getFBPhotos', result.slice(), fnCallback );
			}
			catch ( $_ex )
			{
				statusMsg( 'error during getFBPhotos: ' + $_ex.description );
			}
		});
	});
}

/**
* Get friends of user
*
*/
function getFriends()
{
	statusMsg( "Loading friends..." );

	FB.ensureInit( function()
	{
		//	Get the friend's and their info
		FB.Facebook.apiClient.friends_get( g_sPFUserId, function( result, ex )
		{
			try
			{
				json2xml( 'getFriends', result.slice(), fnCallback );
			}
			catch ( $_ex )
			{
				statusMsg( 'error during getFriends: ' + $_ex.description );
			}
		});
	});
}

/*
 * Our <fb:login-button> specifies this function in its onlogin attribute,
 * which is triggered after the user authenticates the app in the Connect
 * dialog and the Facebook session has been set in the cookies.
 */
function facebook_onlogin_ready()
{
	//	Get the user's ID
	g_sPFUserId = FB.Facebook.apiClient.get_session().uid;
}

/***
* Returns true if user is logged in from facebook...
*/
function isFacebookAlreadyLoggedIn()
{
	return ( null != g_sPFUserId );
}

//********************************************************************************
//*	Stuff a status message in the div (if there)
//********************************************************************************

function statusMsg( msgIn )
{
	FB.FBDebug.writeLine( msgIn );

	var fb_status = document.getElementById( 'fb_status' );

	if ( fb_status )
		fb_status.innerHTML += "<br />" + msgIn;

//	firebug.d.console.cmd.log( msgIn );
}

//********************************************************************************
//*	Parse the query string to get params
//********************************************************************************

function parseQuery( sQuery )
{
	var oParams = new Object();

	if ( sQuery )
	{
		var oPairs = sQuery.split(/[;&]/);

		for ( var i = 0; i < oPairs.length; i++ )
		{
			var sKeyVal = oPairs[ i ].split( '=' );

			if ( ! sKeyVal || sKeyVal.length != 2 )
				continue;

			var sKey = unescape( sKeyVal[ 0 ] );
			var sVal = unescape( sKeyVal[ 1 ] );
			sVal = sVal.replace(/\+/g, ' ');
			oParams[ sKey ] = sVal;
		}
	}

	return( oParams );
}

/**
* Gets the name of the function for calling the back-end api...
*
*/
function getMyName( oArgs )
{
	var sMyName = oArgs.callee.toString();
	sMyName = sMyName.substr( 'function '.length );        		// trim off "function "
	sMyName = sMyName.substr( 0, sMyName.indexOf( '(' ) );		// trim off everything after the function name
	return sMyName;
}

/**
* Used by makeTest
*/
function ajaxTestCallback( sCall, arData, sStatus )
{
	if ( typeof( arData ) != 'string' ) arData = JSON.stringify( arData );
	
	statusMsg( "Ajax call " + sCall + " has completed with the following status '" + sStatus + "'" );
	var sOut = '<div class="test_status">Call status was ' + sStatus + '</div><br />Results:<div class="test_results">' + arData + '</div>';
	$('#test_' + sCall + '_results').html( sOut );
}
	
/***
* Converts a JSON array to XML via web service
*/
function json2xml( sName, arDataIn, fnCallback )
{
	if ( typeof( arDataIn ) != 'string' ) arDataIn = JSON.stringify( arDataIn );
	
	var sData = $.ajax({
		type: 'POST',
		url: g_sBaseUrl,
		async: false,
		global: false,
		data: { c: "json2xml", a1: arDataIn }
	}).responseText;

	if ( fnCallback == 'NOCALLBACK' ) 
		return sData;
		
	if ( typeof( fnCallback ) == 'function' ) 
		g_cbTestAjax( sName, sData, 'success' ); 
	else 
		g_cbAjax( sName, sData, 'success' ); 
}

String.prototype.trim = function () {
	return this.split( /\s/ ).join( " " );
}

String.prototype.convertHTMLEntity = function () {
	var myString = this;
	myString = myString.replace( /\&amp;/g, '&' );
	myString = myString.replace( /\&lt;/g, '<' );
	myString = myString.replace( /\&quot;/g, '"' );
	myString = myString.replace( /\&copy;/g, '©' );
	myString = myString.replace( /\&reg;/g, '®' );
	myString = myString.replace( /\&laquo;/g, '«' );
	myString = myString.replace( /\&raqou;/g, '»' );
//	myString = myString.replace( /\&apos;/g, "'" );
	return myString;
}

/**
* Publishes the results to Facebook.
*
* Expects a string that completes the sentence: So-and-so (did something)
* For example, sending the string 'has been Katamarized! Play now at <link>' results in:
* <CurrentUser> has been Katamarized! Play now at <link>!
*
* @param string $sResults
*
* @return bool
*/
function publishStory( $iStoryType, $sFBInviter, $sFBInvitee, $sNewRank, $iBallSize, $sMessage )
{
	var $_sDesc = $_sTarget = $_sName = null;
	var $_arData = {};
	var $_sImageToUse = "100x100_icon.jpg";

	statusMsg( 'publishStory: type=[' + $iStoryType + '],fbinviter=[' + $sFBInviter + '],fbinvitee=['+$sFBInvitee+'],rank=['+$sNewRank+'],ballsize=['+$iBallSize+'],message=['+$sMessage+']' );
	
	if ( ! $iBallSize || typeof($iBallSize) == 'undefined' ) $iBallSize = 0;
	if ( ! $iStoryType || typeof($iStoryType) == 'undefined' || ( $iStoryType < 0 || $iStoryType > 2 ) ) $iStoryType = 0;
	
	switch ( $iStoryType )
	{
		case 1:		//	Accepted invite
			$_sTarget = new Array( $sFBInviter );
			$_arData['one_line'] = 'made <fb:name uid="' + $sFBInviter + '" useyou="false" firstnameonly="true" />\'s Katamari Forever ball bigger!';
			$_arData['short_story'] = '<fb:name uid="' + g_sPFUserId + '" useyou="false" firstnameonly="true" /> joined <fb:name uid="' + $sFBInviter + '" useyou="false" firstnameonly="true" />\'s Katamari Forever ball and it has grown larger!<br /><br />  You can roll up your friends by getting your very own Katamari Forever ball!<br /><br /><a href="' + g_sAppUrl + '" target="_blank">Click here to roll up your friends!</a>';
			break;
	
		case 2:		//	Ball grew/new rank
			$_sTarget = new Array( $sFBInviter );
			$_arData['one_line'] = 'rocketed <fb:name uid="' + $sFBInviter + '" useyou="false" firstnameonly="true" /> to a HIGHER rank in Katamari Forever!';
			$_arData['short_story'] = '<fb:name uid="' + g_sPFUserId + '" useyou="false" firstnameonly="true" /> joined <fb:name uid="' + $sFBInviter + '" useyou="false" firstnameonly="true" />\'s Katamari Forever ball and <fb:pronoun uid="' + $sFBInviter + '" useyou="false" /> achieved a new rank of ' + $sNewRank + '!<br /><br />  You can roll up your friends by getting your very own Katamari Forever ball!<br /><br /><a href="' + g_sAppUrl + '" target="_blank">Click here to roll up your friends!</a>';
			
			if ( $iBallSize >= 61 && $iBallSize < 81 )
				$_sImageToUse = "100x100_robo.jpg";
			else if ( $iBallSize >= 81 && $iBallSize < 101 )
				$_sImageToUse = "100x100_queen.jpg";
			else if ( $iBallSize >= 101 )
				$_sImageToUse = "100x100_king.jpg";
			break;
			
		default:	//	New user
			$_arData['one_line'] = "has created a Katamari Forever ball!";
			$_arData['short_story'] = 'You can create one too by <a href="' + g_sAppUrl + '" target="_blank">Rolling up your friends</a> and creating the biggest ball in the cosmos! Invite friends to add items to your ball and get rolling! <a href="' + g_sAppUrl + '" target="_blank">Create your own ball</a> now. Big rollers can win crazy prizes like a PS3 or limited edition signed art!<br /><br />Katamari Forever is a fun and exciting new game available on PS3.<br />Free Demo available on PSN.';
			break;
	}
			
	$_arData['images'] = new Array( { 'src' : g_sCallbackUrl + '/' + $_sImageToUse, 'href' : g_sAppUrl } );
	$_arData['target'] = $sFBInviter;
	
	FB.ensureInit( function()
	{
		$_bResult = FB.Connect.showFeedDialog( g_iTemplateId, $_arData, $sFBInviter, '', null, FB.RequireConnect.require, function(postId,exception,data){
			$_sUserData = {'user_data_text':{'inviter':$sFBInviter,'invitee':g_sPFUserId,'postId':postId,'exception':exception,'data':data}};
		    makeAjaxRequest({c:"saveUser",a1:$sFBInviter,a2:$_sUserData}, 'NOCALLBACK' );
			statusMsg( 'showFeedDialog return: postId=[' + postId + '],data=[' + data + ']');
		}, 'Thank you for helping the Prince! Send him a message!', {value: ( $sMessage ? $sMessage : 'I love to Roll Up My Friends with Katamari!' ) } );
	});
	
	return $_bResult;
}
