//MP3 Player...
var MP3PlayerLoaded = false;
var loadedMP3 = null;
soundManager.debugMode = false; // disable debug output
soundManager.url = 'includes/soundmanager2.swf';

soundManager.onload = function() {
  // soundManager should be ready to use/call at this point
  MP3PlayerLoaded = true;
  //show the play button
  var MP3ControlPanel = document.getElementById('mp3Control');
  if (MP3ControlPanel) {
	MP3ControlPanel.style.display = "inline";
  }
  soundManager.createSound('thisMP3', '/music/snippets/' + mp3file);
  loadedMP3 = mp3file;
  //hide the 'download mp3' link
  //var mp3link = document.getElementById('mp3');
  //if (mp3link) {
  //  setVisible(mp3link, 0);
  //}
}

soundOnFinish = function() {
  var controlButton = document.getElementById('MP3controlButton');
  if (controlButton) {
    controlButton.src = "/images/play.gif";
	controlButton.alt = "Play";
  }
}

showProgress = function() {
  soundManager._writeDebug('sound '+this.sID+' playing, '+this.position+' of '+this.duration);	
}

soundOnPlay = function() {
  var controlButton = document.getElementById('MP3controlButton');
  if (controlButton) {
    controlButton.src = "/images/stop.gif";
	controlButton.alt = "Stop";
  }
}

soundManager.onerror = function() {
  // soundManager failed to initialise (security restrictions, no support, missing SWF etc.)
  // Notify user if needed, disable sound-specific functionality etc.
  //alert("Sorry - your browser did not load this Web site's integrated MP3 player.  Perhaps you have not enabled 'Adobe Flash Player' (aka 'Shockwave Flash Plugin') on your browser.\n\nThis means that anywhere you would normally see a link to play an MP3 excerpt of an artist, you'll see a link to download the MP3 file to your computer instead.  Then you'll be able to play them on your favorite MP3 player.");
  //show the 'download mp3' link
  var mp3link = document.getElementById('mp3');
  if (mp3link) {
    mp3link.style.display = "inline";
  }
  return;
}

function playMP3(MP3File) {
  var loading = false;
  if (loadedMP3 != MP3File && loadedMP3 != null) {
    soundManager.destroySound('thisMP3');
    loadedMP3 = null;
  }
  if (loadedMP3 != MP3File) {
    //have to load the file - takes a few seconds, so
	var controlButton = document.getElementById('MP3controlButton');
    if (controlButton) {
      controlButton.src = "/images/loading.gif";
	  controlButton.alt = "Loading MP3 File...";
	  loading = true;
    }
	soundManager.createSound('thisMP3', '/music/snippets/' + MP3File);
	//soundManager.createSound('thisMP3', '/includes/music/snippets/run.mp3');
    loadedMP3 = MP3File;
	
  }
  soundManager.play('thisMP3',{onfinish:soundOnFinish});
  if (loading) {
    setTimeout('soundOnPlay()', 3000);
  }
  return;
}

function stopMP3() {
  soundManager.stop('thisMP3');
  soundOnFinish();
  return;
}

function pauseMP3() {
  soundManager.togglePause('thisMP3');
  return;
}
