/* Setup */
yourURL = 'http://studiomoustache.com/tumblrmp3/'; // The directory on your server of this file. Make sure this includes the trailing '/'

var colorScheme='';

/* Color Scheme
You can change the colors of the player below. Use hex values. More info and a chart of the player elements at http://www.1pixelout.net/code/audio-player-wordpress-plugin/#colours
*/

bg = 'efefef';
leftbg = 'e1e1e1';
lefticon = '333333';
rightbg = 'c5c5c5';
rightbghover = '666666';
righticon = '333333';
righticonhover = 'cccccc';
text = '666666';
slider = '666666';
track = 'dfdfdf';
border = '666666';
loader = 'dfdfdf';

/* Miscellaneous options */

loop = 'no'; // Loops MP3. Options: yes, no
autostart = 'no'; // Starts playing the newest MP3 on page load. Options: yes, no

/* Do not change anything below here */

$(document).ready(function(){
	var counter = 0;
	$('p > b + a[href$=mp3], p > strong + a[href$=mp3]').each(function(){
		mp3URL = $(this).attr('href');
		$(this).parent().html('<object type="application/x-shockwave-flash" data="'+yourURL+'player.swf" id="audioplayer'+counter+'" height="24" width="290"><param name="movie" value="'+yourURL+'player.swf"><param name="FlashVars" value="playerID='+counter+'&amp;bg=0x'+bg+'&amp;leftbg=0x'+leftbg+'&amp;lefticon=0x'+lefticon+'&amp;rightbg=0x'+rightbg+'&amp;rightbghover=0x'+rightbghover+'&amp;righticon=0x'+righticon+'&amp;righticonhover=0x'+righticonhover+'&amp;text=0x'+text+'&amp;slider=0x'+slider+'&amp;track=0x'+track+'&amp;border=0x'+border+'&amp;loader=0x'+loader+'&amp;loop='+loop+'&amp;autostart='+autostart+'&amp;soundFile='+mp3URL+'"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="transparent"></object>');
		counter++;
		if(autostart == 'yes'){autostart = 'no';}
		});
});

var ap_instances = new Array();

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
			else document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName("object");
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
		if(objectID.indexOf("audioplayer") == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );