var IE6 = false;
initSoundManager(null);

var soundReady = false;
var soundInited = false;
/**
  *  Initializes sound manager.  If you would like a sound 
  *  played as soon as sound manager is initialized give the 
  *  url to that sound as the parameter, otherwise give null;
  */
var playPageSound = true; //set this to false to cancel page sound
var soundNum = 0;
var sounds = new Array();
function initSoundManager(soundToPlay, volume) {
	// flash version URL switch (for this demo page)
	if (soundInited){return;}
	if (window.location.toString().match(/flash9/i)) {
  		soundManager.flashVersion = 9;
	} else if (window.location.toString().match(/flash8/i)) {
  		soundManager.flashVersion = 8;
	}
	soundManager.url = '/media/flashResource/swfs/'; // directory where SM2 .SWFs live

	// disable debug mode after development/testing..
	soundManager.debugMode = false;

	soundManager.onload = function() {
   		//SM2 has loaded - now you can create and play sounds!
        soundReady = true;
        if (soundToPlay != null && playPageSound) {
          soundManager.createSound('sound0', soundToPlay);
		  sounds[soundToPlay] = 'sound0';
		  soundNum += 1;
		  if (volume == null) {
 		  	soundManager.play('sound0');
		  }else {
 		  	soundManager.play('sound0', {volume:volume});					
		  }
        }
	}
	soundInited = true;
}

//Plays a sound given the location of the sound.
function EvalSound(soundloc, volume) {
	if (soundReady) {  
		var play;
		if (sounds[soundloc] != null){//sound already exists
		  play = sounds[soundloc];
		}else {//sound doesn't exist so we need to create it
		  soundManager.createSound("sound"+soundNum, soundloc);
		  sounds[soundloc] = "sound"+soundNum;
		  play = "sound"+soundNum;
		  soundNum += 1;
		}
		if( volume == null ) {
	  	  soundManager.play(play); 
		}else {
	  	  soundManager.play(play, {volume:volume});
		}
	}
}
