var currSongIdx=0;
var currSpeakerIdx=0;
var musicPlayer;
var speakerPlayer;

function findeFlash (flash) {
if (document.all) {
  if (document.all[flash]) {
	return document.all[flash];
  }
  if (window.opera) {
	var movie = eval(window.document + flash);
	if (movie.SetVariable) {
	  return movie;
	}
  }
  return;
}
if(document.layers) {
  if(document.embeds) {
	var movie = document.embeds[flash];
	if (movie.SetVariable) {
	  return movie;
	}
  }
  return;
}
if (!document.getElementById) {
  return;
}
var movie = document.getElementById(flash);
if (movie.SetVariable) {
  return movie;
}
var movies = movie.getElementsByTagName('embed');
if (!movies || !movies.length) {
  return;
}
movie = movies[0];
if (movie.SetVariable) {
  return movie;
}
return;
}

function initSounds()
{
	musicPlayer=findeFlash("MusicPlayer");
	speakerPlayer=findeFlash("SpeakerPlayer");

	if (musicPlayer && songList[currSongIdx] != null)
	{
		//musicPlayer.SetVariable("sInfo", "Bitte wählen Sie einen Song aus.");
		musicPlayer.SetVariable("sInfo", songNameList[currSongIdx]);
		musicPlayer.SetVariable("sSoundURL", musicFilePath+songList[currSongIdx]);
	}
	if (speakerPlayer && speakerList[currSpeakerIdx] != null)
	{
		//speakerPlayer.SetVariable("sInfo", "Bitte wählen Sie einen Sprecher aus.");
		speakerPlayer.SetVariable("sInfo", speakerNameList[currSpeakerIdx]);
		speakerPlayer.SetVariable("sSoundURL", speakerFilePath+speakerList[currSpeakerIdx]);
	}
}

function MusicPlayer_DoFSCommand(command, args) { 
  if (command == "OnComplete") {
    musicPlayer.TCallLabel("/Control", "frmPlay");
  }
  else if (command == "OnPrevious") { 
    if (songList[currSongIdx-1] == null)
    {
      currSongIdx = songList.length - 1;
    }
    else
    {
      currSongIdx--;
    }
    PlayMusic(currSongIdx);
  }
  else if (command == "OnNext") { 
    if (songList[currSongIdx+1] == null)
    {
      currSongIdx = 0;
    }
    else
    {
      currSongIdx++;
    }
    PlayMusic(currSongIdx);
  }
  else if (command == "OnPlay") { 
  }
  else if (command == "OnPause") { 
  }
  else if (command == "OnStop") { 
  }
}

function SpeakerPlayer_DoFSCommand(command, args) { 
  if (command == "OnComplete") {
    speakerPlayer.TCallLabel("/Control", "frmPlay");
  }
  else if (command == "OnPrevious") { 
    if (songList[currSpeakerIdx-1] == null)
    {
      currSpeakerIdx = speakerList.length - 1;
    }
    else
    {
      currSpeakerIdx--;
    }
    PlaySpeaker(currSpeakerIdx);
  }
  else if (command == "OnNext") { 
    if (speakerList[currSpeakerIdx+1] == null)
    {
      currSpeakerIdx = 0;
    }
    else
    {
      currSpeakerIdx++;
    }
    PlaySpeaker(currSpeakerIdx);
  }
  else if (command == "OnPlay") { 
  }
  else if (command == "OnPause") { 
  }
  else if (command == "OnStop") { 
  }
}

function PlayMusic(songIdx)
{
	if (songList[songIdx] == null)
    {
	    return false;
    }
	currSongIdx = songIdx;
	musicPlayer.SetVariable("sInfo", songNameList[songIdx]);
	musicPlayer.SetVariable("sSoundURL", musicFilePath+songList[songIdx]);
	musicPlayer.TCallLabel("/Control", "frmLoad");
}

function PlaySpeaker(speakerIdx)
{
	if (speakerList[speakerIdx] == null)
    {
	    return false;
    }
	currSpeakerIdx = speakerIdx;
	speakerPlayer.SetVariable("sInfo", speakerNameList[speakerIdx]);
	speakerPlayer.SetVariable("sSoundURL", speakerFilePath+speakerList[speakerIdx]);
	speakerPlayer.TCallLabel("/Control", "frmLoad");
}

function LoadMusic(songIdx)
{
	if (songList[songIdx] == null)
    {
	    return false;
    }
	currSongIdx = songIdx;
	musicPlayer.TCallLabel("/Control", "frmStop");
	musicPlayer.SetVariable("sInfo", songNameList[songIdx]);
	musicPlayer.SetVariable("sSoundURL", musicFilePath+songList[songIdx]);
}

function LoadSpeaker(speakerIdx)
{
	if (speakerList[speakerIdx] == null)
    {
	    return false;
    }
	currSpeakerIdx = speakerIdx;
	speakerPlayer.TCallLabel("/Control", "frmStop");
	speakerPlayer.SetVariable("sInfo", speakerNameList[speakerIdx]);
	speakerPlayer.SetVariable("sSoundURL", speakerFilePath+speakerList[speakerIdx]);
}

function StopMusic()
{
	musicPlayer.TCallLabel("/Control", "frmStop");
}

function StopSpeaker()
{
	speakerPlayer.TCallLabel("/Control", "frmStop");
}

