$(document).ready(function(){
	var len = $('#audio a[href$=".mp3"]').length;
$('#audio a[href$=".mp3"]').each(function(index,value){
	var text = $(this).text();
	var filename = $(this).attr('href');
	index = (index + 1);	
	$(this).replaceWith(function(){
		return '<div id="jquery_jplayer_'+index+'" class="jp-jplayer"></div><div class="jp-audio"><div id="jp_interface_'+index+'" class="jp-type-single"><div class="jp-interface"><span>'+text+'</span><ul class="jp-controls"><li><a href="#" class="jp-play" tabindex="1">play</a></li><li><a href="#" class="jp-pause" tabindex="1">pause</a></li></ul><div class="jp-progress"><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div><div class="jp-current-time"></div></div></div></div>'
		});
		playerActivate(index,filename);	
		
});

function playerActivate(index,filename){
	var newindex = index;
	if(newindex == len){
		newindex = 1;
		}
	$("#jquery_jplayer_"+index).jPlayer({
		ready: function () {
			$(this).jPlayer("setMedia", {
				mp3: filename
			}).jPlayer("pause");
		},
		ended: function (event) {
			$("#jquery_jplayer_"+newindex).jPlayer("play", 0);
		},
		swfPath: "/radio",
		solution: "flash",
		supplied: "mp3",
		cssSelectorAncestor: "#jp_interface_"+index
	})
	.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
			$(this).jPlayer("pauseOthers");
	});
}
});
