$(document).ready(function(){

	var playItem = 0;

	var myPlayList = [
		{name:"01. Honey",mp3:"/lib/audio/01_Honey.mp3",ogg:"/lib/audio/01_Honey.ogg"},
		{name:"02. I Can't Feel",mp3:"/lib/audio/02_I_Cant_Feel.mp3",ogg:"/lib/audio/02_I_Cant_Feel.ogg"},
		{name:"03. Little People (Black City)",mp3:"/lib/audio/03_Little_People.mp3",ogg:"/lib/audio/03_Little_People.ogg"},
		{name:"04. Slow Dance",mp3:"/lib/audio/04_Slowdance.mp3",ogg:"/lib/audio/04_Slowdance.ogg"},
		{name:"05. Soil to Seed",mp3:"/lib/audio/05_Soil_to_Seed.mp3",ogg:"/lib/audio/05_Soil_to_Seed.ogg"},
		{name:"06. You Put a Smell on Me",mp3:"/lib/audio/06_You_Put_A_Smell_On_Me.mp3",ogg:"/lib/audio/06_You_Put_A_Smell_On_Me.ogg"},
		{name:"07. Shortwave",mp3:"/lib/audio/07_Shortwave.mp3",ogg:"/lib/audio/07_Shortwave.ogg"},
		{name:"08. Monkey",mp3:"/lib/audio/08_Monkey.mp3",ogg:"/lib/audio/08_Monkey.ogg"},
		{name:"09. More Surgery",mp3:"/lib/audio/09_More_Surgery.mp3",ogg:"/lib/audio/09_More_Surgery.ogg"},
		{name:"10. Gem",mp3:"/lib/audio/10_Gem.mp3",ogg:"/lib/audio/10_Gem.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(false); // 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 );
	}
});


function checkEmail() {
	var email = document.getElementById('kjtdki-kjtdki');
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) {
		alert('Please check your typing. The email address needs to be valid.');
		email.focus
		return false;
	}
}