// TRACKLISTING PLAYER
// simple play/stop player that plays the href of an <a> element with the class .play
//eg: <a href="trackname.mp3" class="play">play</a>

$(document).ready(function(){

//put a stop after every play
$(".play").after("<a class='stop' href='#'>Stop</a>");


//hide play if there is no track
 $(".play").each(function(){
                    var track = $(this).attr("href"); 
                    if (track === false)
                    {$(this).css({"visibility":"hidden"});}
                     
                    else if (track === "")
                     {$(this).css({"visibility":"hidden"});}
                   else {}
                   // $("<li>").text($this.attr("id")+text).appendTo($("ul"));
                });    


   $("#jquery_jplayer").jPlayer({
		ready: function () {}
	});

 	function playTrack(t)
	{
		$("#jquery_jplayer").setFile(t).play();
        return false;
	}

 
	$(".play").click(function() {
 	$(".stop").css({"display":"none"});
	$(".play").css({"display":"block"});
	$(this).css({"display":"none"});
	$(this).next(".stop").css({"display":"block"});
 	return(playTrack($(this).attr("href")));
 	return false
 	});

 
 
	$(".stop").click(function() {
		$("#jquery_jplayer").stop();
		$(this).css({"display":"none"});
		$(this).prev(".play").css({"display":"block"});
		return false;
	});

    // change button back when track finishes
	$("#jquery_jplayer").onSoundComplete( function() { 
	$(".stop").css({"display":"none"});
	$(".play").css({"display":"block"});
	});

});

