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

/**
 * 
 * PLAYER FUNCTIONS
 *  
 */

/**
 * Returns true if the Player is logged in (anonymously or into Clay.io)
 */
function clay_player_logged_in()
{
	return Clay['Player'] ? ( Clay['Player']['isLoggedIn'] ) : false;
}

/**
 * Returns "clay", "site", or "none" depending on what the player is logged into
 */
function clay_player_clearance()
{
	return Clay['Player'] ? ( Clay['Player']['clearance'] ) : 'none';
}

/**
 * Brings up the prompt to log a player into Clay.io 
 */
Clay['gamemaker']['loggedInComplete'] = false;
function clay_player_login()
{
	Clay['gamemaker']['loggedInComplete'] = false;
	Clay['Player']['login']( function( response ) {
		if( response.success )
			Clay['gamemaker']['loggedInComplete'] = {};    
	} );
}
function clay_player_logged_in_ready()
{
	return clay_check_ready( Clay['gamemaker']['loggedInComplete'] );
}

Clay['gamemaker']['fetchedItems'] = false;
function clay_player_fetch_items()
{
	Clay['gamemaker']['fetchedItems'] = false;
	Clay['Player']['fetchItems']( function( items ) {		
		Clay['gamemaker']['fetchedItems'] = items;
	} );
}
function clay_player_fetched_items_ready()
{
	return clay_check_ready( Clay['gamemaker']['fetchedItems'] );
}
function clay_player_fetched_items_count()
{
	if( clay_player_fetched_items_ready() )
		return Clay['gamemaker']['fetchedItems']['length'];
}
function clay_player_fetched_items_item_at( index )
{
	if( clay_player_fetched_items_ready() )
		return Clay['gamemaker']['fetchedItems'][ index ];
}
