var Clay = Clay || {};
// GameMaker related data is stored here... (a lot of callback stuff)
Clay['gamemaker'] = Clay['gamemaker'] || {};

/**
 * 
 * SOCIAL FUNCTIONS
 *  
 */

/**
 * Posts a message to Facebook
 * @param {String} message
 * @param {String} url
 * @param {String} picture - URL to picture to post 
 */
Clay['gamemaker']['facebookPosted'] = false;
function clay_facebook_post( message, url, picture )
{
	var fb = new Clay['Facebook']();

	var options = { message: message };
	if( url != '' )
		options['link'] = url;
	if( picture != '' )
		options['picture'] = picture;

	Clay['gamemaker']['facebookPosted'] = false;
	fb.post( options, function( response ) {
	    if( response.success )
			Clay['gamemaker']['facebookPosted'] = {};
	} );
}

/**
 * Returns true when Facebook message is posted 
 */
function clay_facebook_posted_success()
{
	return clay_check_ready( Clay['gamemaker']['facebookPosted'] );
}

/**
 * Opens modal for inviting Facebook friends
 */
Clay['gamemaker']['facebookInvited'] = false;
function clay_facebook_invite_friends( caption )
{
	Clay['gamemaker']['facebookInvited'] = false;
	var options = {};
	if( caption !== '' )
		options['caption'] = caption;
	Clay.Facebook.invite( options, function( response ) {
	    if( response.success )
			Clay['gamemaker']['facebookInvited'] = {};
	} );
}

/**
 * Returns true when Facebook message is posted 
 */
function clay_facebook_invite_friends_success()
{
	return clay_check_ready( Clay['gamemaker']['facebookInvited'] );
}


/**
 * Posts a message to Twitter
 * @param {String} message
 */
Clay['gamemaker']['twitterPosted'] = false;
function clay_twitter_post( message )
{
	var twitter = new Clay['Twitter']();

	var options = { message: message };

	Clay['gamemaker']['twitterPosted'] = false;
	twitter.post( options, function( response ) {
	    if( response.success )
			Clay['gamemaker']['twitterPosted'] = {};
	} );
}

/**
 * Returns true when Facebook message is posted 
 */
function clay_twitter_posted_success()
{
	return clay_check_ready( Clay['gamemaker']['twitterPosted'] );
}

/**
 * Posts a message to the Clay.io Stream
 * @param {String} message
 */
Clay['gamemaker']['streamPosted'] = false;
function clay_stream_post( message )
{
	var stream = new Clay['Stream']();

	var options = { message: message };

	Clay['gamemaker']['streamPosted'] = false;
	stream.post( options, function( response ) {
	    if( response.success )
			Clay['gamemaker']['streamPosted'] = {};
	} );
}

/**
 * Returns true when Facebook message is posted 
 */
function clay_stream_posted_success()
{
	return clay_check_ready( Clay['gamemaker']['streamPosted'] );
}