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

/**
 * 
 * DATA FUNCTIONS
 *  
 */

Clay['gamemaker']['dataSaved'] = {};
function clay_data_save( key, data )
{
	delete Clay['gamemaker']['dataSaved'][ key ];
	Clay['Player']['saveUserData']( key, data, function( response ) {
		if( response.success )
			Clay['gamemaker']['dataSaved'][ key ] = response;
		else
			Clay['log']( response.error );	    
	} );
}
function clay_data_saved_ready( key )
{
	return clay_check_ready( Clay['gamemaker']['dataSaved'][ key ] );
}

Clay['gamemaker']['dataFetched'] = {};
function clay_data_fetch( key )
{
	delete Clay['gamemaker']['dataSaved'][key];
	Clay['Player']['fetchUserData']( key, function( response ) {
		Clay['gamemaker']['dataFetched'][ key ] = response;	    
	} );
}
function clay_data_fetched_ready( key )
{
	return clay_check_ready( Clay['gamemaker']['dataFetched'][ key ] );
}
function clay_data_fetched_data( key )
{
	if( clay_data_fetched_ready( key ) )
	{
		return Clay['gamemaker']['dataFetched'][ key ]['data'];
	}
}