$(document).ready(function(){
 
	var playItem = 0;
 
	var myPlayList = [
		{name:"1. You're Still You",mp3:"/markvincent/mp3/01.mp3",ogg:"/markvincent/mp3/01.ogg"},
		{name:"2. Amazing Grace",mp3:"/markvincent/mp3/02.mp3",ogg:"/markvincent/mp3/02.ogg"},
		{name:"3. Non Ti Scordar Di Me",mp3:"/markvincent/mp3/03.mp3",ogg:"/markvincent/mp3/03.ogg"},
		{name:"4. Till I Hear You Sing",mp3:"/markvincent/mp3/4.mp3",ogg:"/markvincent/mp3/4.ogg"},
		{name:"5. Young At Heart",mp3:"/markvincent/mp3/5.mp3",ogg:"/markvincent/mp3/5.ogg"},
		{name:"6. Wishing You Were Somehow Here Again",mp3:"/markvincent/mp3/6.mp3",ogg:"/markvincent/mp3/6.ogg"},
		{name:"7. Climb Every Mountain",mp3:"/markvincent/mp3/7.mp3",ogg:"/markvincent/mp3/7.ogg"},
		{name:"8. Cavatina",mp3:"/markvincent/mp3/8.mp3",ogg:"/markvincent/mp3/8.ogg"},
		{name:"9. If Ever I Would Leave You",mp3:"/markvincent/mp3/9.mp3",ogg:"/markvincent/mp3/9.ogg"},
		{name:"10. Bridge Over Troubled Water",mp3:"/markvincent/mp3/10.mp3",ogg:"/markvincent/mp3/10.ogg"},
		{name:"11. Mi Manchi",mp3:"/markvincent/mp3/11.mp3",ogg:"/markvincent/mp3/11.ogg"},
		{name:"12. Forever And Ever",mp3:"/markvincent/mp3/12.mp3",ogg:"/markvincent/mp3/12.ogg"},
		{name:"13. Once Before I Go On",mp3:"/markvincent/mp3/13.mp3",ogg:"/markvincent/mp3/13.ogg"},
		{name:"14. My Heart Will Go On",mp3:"/markvincent/mp3/14.mp3",ogg:"/markvincent/mp3/14.ogg"}
		
	];
 
	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");
	//var jpStatus = $("#demo_status"); // For displaying information about jPlayer's status in the demo page
	
	$("#jquery_jplayer").jPlayer({
		ready: function() {
			displayPlayList();
			playListInit(false); // Parameter is a boolean for autoplay.
			//demoInstanceInfo(this.element, $("#demo_info")); // This displays information about jPlayer's configuration in the demo page
		},
		oggSupport: true,
		swfPath: "/humannature/flash/"
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
 
		//demoStatusInfo(this.element, jpStatus); // This displays information about jPlayer's status in the demo page
	})
	.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 );
	}
});

