/**
 * The Syn.Radio Component Class
 */ 

/**
 * Create a Syn.Radio component instance
 * @constructor
 */
Syn.Radio = Syn.Component.extend(
{
	/**
	 * Initialize the component class. This is called automatically by the default constructor.
	 * @member Syn.Radio
	 * @param {Object} config
	 */
	init: function(config)
	{
		this._super(config);

		this.uniqueElmt('listen').connect('click',this,'onListenClick');
		this.uniqueElmt('add_to_favorites').connect('click',this,'addToFavorites');
		
		for (var i=0; this.uniqueElmt('favorite_station'+i).length; i++)
		{
			this.uniqueElmt('favorite_station'+i).connect('click',this,'launchMusicChannnel');
		}

		for (var i=0; this.uniqueElmt('remove_from_favorites'+i).length; i++)
		{
			this.uniqueElmt('remove_from_favorites'+i).connect('click',this,'removeFromFavorites');
		}


	},

	/**
         * Launches music channel when a link is clicked (in favorites)
         * @member Syn.Radio
         */
        launchMusicChannnel: function(elmt,ev)
        {
		window.open($(elmt).attr('rel'), 'Radio','toolbar=no,menubar=no,location=no,resizeable=no,status=no,height=283,width=728');
	},

	/**
         * Remove game from list of user's favorites
         * @member Syn.Radio
         */
        removeFromFavorites: function(elmt,ev)
        {
                this.submit({'remove':$(elmt).attr('rel')});
        },

	/**
	 * Adds game to list of user's favorites
	 * @member Syn.Radio
	 */
	addToFavorites: function(elmt,ev)
	{
		this.submit({'add':this.uniqueElmt('channel').attr('value')});
	},


	/**
	 * Launches the selected radio channel when Listen Button is clicked
	 * @member Syn.Radio
	 */
	onListenClick: function(elmt,ev)
	{
		window.open($(elmt).attr('rel')+'&station_title='+this.uniqueElmt('channel').attr('value'), 'Radio','toolbar=no,menubar=no,location=no,resizeable=no,status=no,height=283,width=728');
	}

});
