
	$(document).ready(function() {
		var ICON_WAIT_SEC = 3;
		var loadWaitDisplayerID;
		var jqSoundHosts = $("a[href$=.mp3]");

		// prepare controls
		jqSoundHosts.each(function(i,el){
			var linkText = $(this).text();
			$(this)
				.html('<span class="play">play</span><span class="stop">stop</span>')
				.after('<b>' + linkText + '</b>');
		});


		// setup control behaviors

		$("a[href$=.mp3]").click(function(){
			if ($.dbj_sound.playing(this)) {
				// toggle sound off
				$.dbj_sound.stop(this);
				$(this).parent("li").removeClass("playing");
				hideWaitIcon();
			} else {
				// play only this sound
				stopAllSounds();
				$.dbj_sound.play(this);
				$(this).parent("li").addClass("playing");
				cueWaitIcon();
			}
			return false;
		});
		$("a[href$=.mp3]").siblings("b").click(function(){
			$(this).siblings("a").click();
		});

		function stopAllSounds () {
			jqSoundHosts.each(function(i,el){
				$.dbj_sound.stop(this);
				$(this).parent("li").removeClass("playing");
			});
		}

		function cueWaitIcon () {
			$("#loadWaitIcon").show();
			loadWaitDisplayerID = setInterval(hideWaitIcon, ICON_WAIT_SEC * 1000);
		}

		function hideWaitIcon () {
			$("#loadWaitIcon").hide();
			clearInterval(loadWaitDisplayerID);
		}

	});