
$(document).ready(function(){

	/* GLOBAL SIDEBAR PLAYLIST
	-------------------------------------------------------------------*/
	var audioPlaylist = new Playlist("1", [
		{
			name:"Slightly Off Course",
			mp3: base+"/wp-content/audio/SlightlyOffCourse-short.mp3"
		},
		{
			name:"Wave",
			mp3: base+"/wp-content/audio/Wave.mp3"
		},
		{
			name:"Miyako",
			mp3: base+"/wp-content/audio/Miyako.mp3"
		},

	], {
		ready: function() {
			audioPlaylist.displayPlaylist();
			audioPlaylist.playlistInit(false); // Parameter is a boolean for autoplay.
		},
		ended: function() {
			audioPlaylist.playlistNext();
		},
		play: function() {
			$(this).jPlayer("pauseOthers");
		},
		swfPath: "/wp-content/themes/antonjazz/js/jplayer/",
		supplied: "mp3"
	});



	/* CD AUDIO SAMPLES
	-------------------------------------------------------------------*/
	
	// LOOP THROUGH ALL PLAYERS AND LOAD MEDIA SPECIFIED IN THE data-sample ATTRIBUTE
	var playerCount = 1;
	$('.cdContainer').live('loadPlayer',function() {
		var sample = '',
			player = [],
			current = {};

		playerCount++;
		current = this;
		player = $(current).children('.jp-jplayer');
		current.sample = player[0].getAttribute('data-sample');

		if(current.sample) {
			// INITIALIZE MEDIA PLAYER
			$("#jquery_jplayer_"+playerCount).jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: current.sample
					});
				},
				ended: function (event) {
					//$("#jquery_jplayer_"+playerCount).jPlayer("play", 0);
				},
				swfPath: "/wp-content/themes/antonjazz/js/jplayer/",
				supplied: "mp3",
				cssSelectorAncestor: "#jp_interface_"+playerCount
			}).bind($.jPlayer.event.play, function() {
				// Avoid both jPlayers playing together
				$(this).jPlayer("pauseOthers");
			});
		} else {
			// no sample provided: hide player controls
			$(current).children('.jp-audio').css('display','none');
		}
	});
});
