soundManager.url = '../_swf/';
soundManager.debugMode = false;
document.observe('dom:loaded', function () {
	soundManager.onload = function () {
		$$('a[href$=.mp3]').each(function (link, player_id) {
			var playing = false;
			var total_loaded = new Element('span', { className: 'total_loaded' });
			var play_progress = new Element('span', { className: 'play_progress' });
			link.addClassName('mp3_link').insert(total_loaded).insert(play_progress);
			var max_width = link.getWidth();
		
			var player = soundManager.createSound({
				id: 'mp3player_' + player_id, // required
				url: link.readAttribute('href'), // required
				autoPlay: false,
				whileloading: function () {
					var width = this.bytesLoaded / this.bytesTotal * max_width;
					total_loaded.setStyle({ 'width': width + 'px' });
				},
				whileplaying: function () {
					var width = this.position / this.duration * max_width;
					play_progress.setStyle({ 'width': width + 'px' });
				},
				onload: function () {
					total_loaded.setStyle({ 'width': max_width + 'px' });
				}
			});
		
			link.observe('click', function (event) {
				event.stop();
				playing = !playing;
				
				if (playing) {
					this.setStyle({ 'backgroundPosition': '0 -21px' });
					player.play();
				} else {
					this.setStyle({ 'backgroundPosition': '0 0' });
					player.pause();
				}
			});
		});
	}
});

