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

/**
 * 
 * ADVERTISING FUNCTIONS
 *  
 */

/**
 * Creates and displays an advertisement
 * @param {String} size
 * @param {String} top - Distance from top of game canvas. Can be integer (# of pixels) or string "##%" 
 * @param {String} right - Distance from right of game canvas. Can be integer (# of pixels) or string "##%" 
 * @param {String} bottom - Distance from bottom of game canvas. Can be integer (# of pixels) or string "##%" 
 * @param {String} left - Distance from left of game canvas. Can be integer (# of pixels) or string "##%" 
 * @param {String} reference - 'default' or 'center'. Is the reference point. Eg. left: 50% with reference: 'center' means the center of the ad is 50% from the left
 * @param {Integer} refreshInterval - How often the advertisement refreshes (minimum 30 seconds)
 * @return {Integer} advertisement ID (for manipulating later)
 */

Clay['gamemaker']['advertisements'] = [];
Clay['gamemaker']['advertisementsIndex'] = 0;
function clay_advertisement( size, top, right, bottom, left, reference, refreshInterval )
{
	var options = {
		size: size,
		position: {
			parent: document.getElementById( 'gm4html5_div_id' )
		},
		refreshInterval: refreshInterval
	};
	
	if( reference == 'center' )
		options['position']['reference'] = 'center';
	
	if( typeof top !== 'undefined' && top !== -1 )
		options['position']['top'] = top;
	if( typeof left !== 'undefined' && left !== -1 )
		options['position']['left'] = left;
	if( typeof bottom !== 'undefined' && bottom !== -1 )
		options['position']['bottom'] = bottom;
	if( typeof right !== 'undefined' && right !== -1 )
		options['position']['right'] = right;
		
	Clay.ready( function() {
		Clay['gamemaker']['advertisements'].push( new Clay['Advertisement']( options ) );
	} );
	console.log( Clay['gamemaker']['advertisementsIndex'] );
	return Clay['gamemaker']['advertisementsIndex']++;
}

function clay_advertisement_show( id )
{
	if( Clay['gamemaker']['advertisements'][ id ] )
		Clay['gamemaker']['advertisements'][ id ].show();
}

function clay_advertisement_hide( id )
{
	if( Clay['gamemaker']['advertisements'][ id ] )
		Clay['gamemaker']['advertisements'][ id ].hide();
}
