// Original concept from: http://willswonders.myip.org:8085/php/Multiple%20Players.html
var cmlh = '';	// Current M3U Link HTML
var ceid = '';	// Current Element ID
var embedStatus = false;

function outputStatus(e)
{
	embedStatus = ! e.success;
}

function loadButtonPlayer(e)
{
	// Account for "MP3 download whole song, hi-fi" option
	if($('#'+e.id).attr('href').match(/.mp3$/))
	{
		return true;
	}

	var music_file	= encodeURIComponent($('#'+e.id).attr('href').replace(/.m3u$/, '.mp3'));
	var button_path	= '/shared/lib/images/audioplay_buttons/classic_small';
	var swf			= '/shared/lib/swf/audioplay.swf';

	// Restore original button span and m3u anchor link of previous button player.
	if(cmlh !== '')
	{
		$('#'+ceid).parent().html(cmlh);
	}
	// Save the original button span and m3u anchor html
	cmlh = $('#'+e.id).parent().html();
	// Save current page element's id
	ceid = e.id;

	// http://www.strangecube.com/audioplay/
	var flashvars = {
		auto:			'yes',			// auto - autostart (yes|no), default no
		bgcolor:		'0xa9a9a9',		// bgcolor - background color (color in hex format, 0xff0000 for red for example), default 0x000000 (black)
		repeat:			'1',			// repeat - how many times music will be played, 0 - infinite loop, default setting
		file:			music_file,		// file - music file path, default 'music.mp3'
		buttondir:		button_path,	// buttondir - path to button directory, default 'buttons/classic'
	//	mode:			'playpause',	// mode - select player mode: 'playpause' (default) or 'playstop' (stop button stops streaming)
	//	listenstop:		'yes',			// listenstop - stop/pause after clicking play on other player, default 'yes'
	//	sendstop:		'yes',			// sendstop - send stop/pause command to other players after play button click, default 'yes'
	//	trackid:		'',				// trackid - unique track id (used with 'nexttrack' parameter), default empty (NEW !)
	//	nexttrack:		'',				// nexttrack - which player will start after playing will be finished, default empty (NEW !)
		usebgcolor:		'yes',			// usebgcolor - disables transparency if set to 'yes', 'bgcolor' will be used as background, default 'no' (NEW !)
	//	fadeindur:		'0',			// fadeindur - alpha fade-in duration, default 0 (NEW !)
		mastervol:		'100'			// mastervol - master volume (0-100), default 100 (NEW !)
	};
	var params = { };
	var attributes = { };

	swfobject.embedSWF(swf, 'button_'+e.id, '15', '15', '9', false, flashvars, params, attributes, outputStatus);

	// if true, prevents the .m3u from being downloaded.
	// else, no Flash, so offer the .m3u file.
	return embedStatus;
}
