/*

this script require jquery

i named the id of the flash object as 'flashMP3player'


the songs has to be inside a div with class="songs"
each song is: <a href="#" onclick="play('song_file.mp3',this);return false;">Song Name</a><br />

example:
<div class="songs">
	<a href="#" onclick="play('05-Glacier Lady.mp3',this);return false;">Glacier Lady</a><br />
	<a href="#" onclick="play('12-Lumberjack.mp3',this);return false;">Lumberjack</a><br />
</div>

*/

var thisFolder = '/inc/neolao-flash-mp3-player/';
var mp3Folder = ''; // to use ONLY if is not specified on the link itself


var singing;
var myListener = new Object();

/**
 * Initialize
 */
myListener.onInit = function()
{
	this.position = 0;
};
/**
 * Update
 */
myListener.onUpdate = function()
{
	if (singing!=null) {
		if ($(".songs a").eq(singing).hasClass('stop')) {
			$(".songs a").eq(singing).removeClass('stop').addClass('stopblue');
		} else if ($(".songs a").eq(singing).hasClass('stopblue')) {
			$(".songs a").eq(singing).removeClass('stopblue').addClass('stop');
		}
	}
			
		//if ($(singing).hasClass('stop')) {
		//	$(singing).removeClass('stop').addClass('stopblue');
		//} else if ($(singing).hasClass('stopblue')) {
		//	$(singing).removeClass('stopblue').addClass('stop');
		//}
};

/**
 * private functions
 */
function _getFlashObject()
{
	return document.getElementById("flashMP3player");
}

/**
 * public functions
 */
function resetPlayButtons() {
	$(".songs a").removeClass().addClass('');
}

function play(song,ind) {
	$(".songs a").eq(ind).blur();
	resetPlayButtons();
	if (singing==ind) {
		stop();
		singing=null;
	} else {
		singing=ind;
		$(".songs a").eq(singing).addClass('stop');
		_getFlashObject().SetVariable("method:setUrl", mp3Folder + song); //++++++++++++
		_getFlashObject().SetVariable("method:play", "");
		_getFlashObject().SetVariable("enabled", "true");
	}
	//return false;
}
function pause() {
    _getFlashObject().SetVariable("method:pause", "");
}
function stop() {
    _getFlashObject().SetVariable("method:stop", "");
}


var str_flashMP3player = '\n<object id="flashMP3player" type="application/x-shockwave-flash" data="' + thisFolder + 'player_mp3_js.swf" width="1" height="1">';
str_flashMP3player += '<param name="movie" value="' + thisFolder + 'player_mp3_js.swf" />';
str_flashMP3player += '<param name="AllowScriptAccess" value="always" />';
str_flashMP3player += '<param name="FlashVars" value="listener=myListener&amp;interval=500" />';
str_flashMP3player += '</object>\n';

$(document).ready(function() {
	//prepend the flash object if is not manually inserted
	if ($("body").has("#flashMP3player").length==0) {
		$("body").prepend(str_flashMP3player);
	}
	
	//transform the links inside the "songs" divs
	// from: <a href="/mp3/samples/crinoline/05-Glacier%20Lady.mp3">4. He’s on Vacation</a>
	// to:   <a href="#" onclick="play('/mp3/samples/crinoline/05-Glacier%20Lady.mp3',this);return false;">4. He’s on Vacation</a>
	//$(".songs a").each(function(index) {
	//	href_string = $(this).attr('href');
	//	text_string = $(this).text();
	//	//alert(href_string + '\n' + text_string);
	//	$(this).attr('href',"javascript:play('"+ href_string + "',this)");
	//	//$(this).attr('onclick',"play('"+ href_string + "',this);return false;");
	//});
	
});



//CSS + PATCH FOR INTERNET EXPLORER COMMUNICATION WITH FLASH
document.writeln('\n<!--[if IE]>');
document.writeln('<script type="text/javascript" event="FSCommand(command,args)" for="flashMP3player">');
document.writeln('eval(args);');
document.writeln('</script>');
document.writeln('<![endif]-->');
document.writeln('');
document.writeln('<style type="text/css" media="screen"><!--');
document.writeln('@import url(' + thisFolder + 'player_mp3_js.css);');
document.writeln('--></style>');

