$(document).ready(function(){
 
	var playItem = 0;
 
	var myPlayList = [{name:"She Became The Sun",mp3:"songs/zjAYc02SheBecametheSun.mp3"},{name:"Kaleidoscope",mp3:"songs/erjW401Kaleidoscope.mp3"},{name:"Fantasy Man",mp3:"songs/u40IT07FantasyMan.mp3"},{name:"Looking Glass",mp3:"songs/cEjeb04LookingGlass.mp3"},{name:"Lone Rider",mp3:"songs/pzahE01LoneRider.mp3"},{name:"My Little Secret",mp3:"songs/V10Q902MyLittleSecret2.mp3"}];
 
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");
	
	$("#jquery_jplayer_album").jPlayer({
		ready: function() {
			displayPlayList();
			playListInit(false);
		},
		oggSupport: false
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});
	$("#player_album").click(playPlayer_album);
	
	function playPlayer_album(a) {
		$("#jquery_jplayer_album").jPlayer("play");
	}
	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_album").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_album").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}
 
	function playListChange( index ) {
		playListConfig( index );
		$("#jquery_jplayer_album").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 );
	}
	
	$("#_vid a").click(function() {
		$("#jquery_jplayer_album").jPlayer("pause")
		return false;
	});
});
