/**
 * Flash games javascript class
 */

/**
 * Create a Syn.games_free_online component instance
 * @constructor
 */
Syn.GamesFreeOnline = Syn.Component.extend (
{
	/**
	 * Initialize the component class. This is called automatically by the default constructor.
	 * @member Syn.FlashGames
	 * @param {Object} config The configuration data structure
 	*/
	init: function(config)
	{
		this._super(config);
		this.page_index = config['page_index'];
		this.game_name  = config['game_name'];
		this.game_url   = config['game_url'];
		
		this.uniqueElmt('next').connect('click',this,'submit',[ {page_index:this.page_index+8} ])
		                                 .connect('click',this,'showLoading');
		this.uniqueElmt('prev').connect('click',this,'submit',[ {page_index:this.page_index-8} ])
		                                 .connect('click',this,'showLoading');

		for (var i=0; this.uniqueElmt('game'+i).length; i++)
		{
			this.uniqueElmt('game'+i).find('a').connect('click',this,'launchGame');
		}

		for (var i=0; this.uniqueElmt('game_list'+i).length; i++)
		{
			this.uniqueElmt('game_list'+i).find('a').connect('click',this,'launchGame');
		}

	},

	/**
	 * Shows loading graphic when retrieving data
	 * @member Syn.FlashGames
	 */
	showLoading: function()
	{
		this.uniqueElmt('loading').show().css( { 'width':this.container().width(), 'height':this.container().height() } );
	},

	/**
	 * Launches the popup window with the flash game
	 * @member Syn.FlashGames
	 */
	launchGame: function (elmt,ev)
	{
		this.submit({'log_game_token':$(elmt).attr('rel'),page_index:this.page_index}, {norender:true});
	}

});

