$(document).ready(function(){

	var playItem = 0;

	var myPlayList = [
		{name:"<img src=\"playerfiles/sullendercater.jpg\" align=\"right\" border=\"0\" hspace=\"5\"  />Woody Sullender & Seamus Cater<br /><em>While Sails Billow</em><br />from <em>Live at Barkenhoff</em>",
		mp3:"http://deadceo.com/playerfiles/sullendercater.mp3",
		ogg:"http://deadceo.com/playerfiles/sullendercater.ogg"},

		{name:"<img src=\"playerfiles/zaum.jpg\" align=\"right\" border=\"0\" hspace=\"5\"  />Ivanovich<br /><em>Dendrite</em><br />from <em>Zaum</em>",
		mp3:"http://deadceo.com/playerfiles/ivanovich.mp3",
		ogg:"http://deadceo.com/playerfiles/ivanovich.ogg"},
		{name:"<img src=\"playerfiles/ianepps.png\" align=\"right\" border=\"0\" hspace=\"5\"  />Ian Epps<br /><em>track 5</em><br />from <em>Audiophone</em>",
		mp3:"http://deadceo.com/playerfiles/audiophone_track05.mp3",
		ogg:"http://deadceo.com/playerfiles/audiophone_track05.ogg"},
		{name:"<img src=\"playerfiles/winterconstruction.jpg\" align=\"right\" border=\"0\" hspace=\"5\"  />Flying Luttenbachers<br /><em>Trauma II</em><br />from <em>Winter Construction</em>",
		mp3:"http://deadceo.com/playerfiles/flyingluttenbachers.mp3",
		ogg:"http://deadceo.com/playerfiles/flyingluttenbachers.ogg"},
		{name:"<img src=\"playerfiles/liveatbark.jpg\" align=\"right\" border=\"0\" hspace=\"5\"  />Uncle Woody Sullender<br />excerpt from <em>Volkslied</em><br />from <em>Live at Barkenhoff</em>",
		mp3:"http://deadceo.com/playerfiles/sullender_violence_exc.mp3",
		ogg:"http://deadceo.com/playerfiles/sullender_violence_exc.ogg"},
		{name:"<img src=\"playerfiles/zaum.jpg\" align=\"right\" border=\"0\" hspace=\"5\"  />Repetophile<br /><em>A Story about Logs </em><br />from <em>Zaum</em>",
		mp3:"http://deadceo.com/playerfiles/repetophile.mp3",
		ogg:"http://deadceo.com/playerfiles/repetophile.ogg"}
		
	
	];

	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");

	$("#jquery_jplayer").jPlayer({
		ready: function() {
			displayPlayList();
			playListInit(true); // Parameter is a boolean for autoplay.
		},
		oggSupport: true
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});

	$("#jplayer_previous").click( function() {
		playListPrev();
		$(this).blur();
		return false;
	});

	$("#jplayer_next").click( function() {
		playListNext();
		$(this).blur();
		return false;
	});

	function displayPlayList() {
		$("#jplayer_playlist ul").empty();
		for (i=0; i < myPlayList.length; i++) {
			var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
			listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a></li>";
			$("#jplayer_playlist ul").append(listItem);
			$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
				var index = $(this).data("index");
				if (playItem != index) {
					playListChange( index );
				} else {
					$("#jquery_jplayer").jPlayer("play");
				}
				$(this).blur();
				return false;
			});
		}
	}

	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem );
		}
	}

	function playListConfig( index ) {
		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
		playItem = index;
		$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		playListConfig( index );
		$("#jquery_jplayer").jPlayer("play");
	}

	function playListNext() {
		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
		playListChange( index );
	}

	function playListPrev() {
		var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
		playListChange( index );
	}
});
