<!--
var scrollSpeed = 200;
var scrollChars = 1;
var songName;
var paused = false;
var nro = 0;
var total = 0;
var songs = new Array();
var playing;
var songNumber;
var newMusic;
var timeoutID;
var watching;
var milliseconds;
var seconds;
var startTime;
var msgVis;
var firstsong = true;
var newWin;
var tRecomeca=3000;
var recomecaID;
var estavatocando;
var stoppressed=false;

function Tune(tuneFile,tuneName,tuneArtist,tuneTime) 
{
  this.tuneFile = tuneFile;
  this.tuneName = tuneName;
  this.tuneArtist = tuneArtist
  this.tuneTime = tuneTime;
}


function setTune(tuneFile,tuneName,tuneArtist,tuneTime) 
{
  songs[nro ++] = new Tune(tuneFile,tuneName,tuneArtist,tuneTime);
  total += tuneTime;
}



function startTimer() 
{
  timeoutID = setTimeout('keepWatching()', 1000);
  watching = true;
}


function stopTimer() 
{
  clearTimeout(timeoutID);
  watching = false;
}


function keepWatching() 
{
  controlTrackAndTime();
  if (playing) {timeoutID = setTimeout('keepWatching()', 1000);}
}


function resetstartTime() 
{
  now = new Date();
  startTime = Date.UTC(now.getYear(),now.getMonth(),now.getDate(),now.getHours(),now.getMinutes(),now.getSeconds());
  milliseconds = 0;
  seconds = 0;
}


function controlTrackAndTime() 
{
  wasPlaying = playing;
  now = new Date();
  milliseconds = Date.UTC(now.getYear(),now.getMonth(),now.getDate(),now.getHours(),now.getMinutes(),now.getSeconds()) - startTime;
  seconds = (milliseconds / 1000) - 1;
  if (seconds == -1) {seconds = 0;}
 
  if (seconds > songs[songNumber].tuneTime) {next();}
}


function getRandomNum(lbound, ubound) 
{
  //return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
  return (Math.round(Math.random() * (ubound - lbound)) + lbound);
}


function initMusic()
{

  if (document.layers) 
  {
    visib = 'show';
    invib = 'hide';
    msgVis = document.msgPlace;
  } else {
    visib = 'visible';
    invib = 'hidden';
    msgVis = msgPlace.style;
  }
  
//  if (document.all) 
//  {
//    visib = 'visible';
//    invib = 'hidden';
//    msgVis = msgPlace.style;
//  }
  msgVis.visibility = invib;
  scrollMarquee();
  setTrack();
}


function getSong()
{
  msgVis.visibility = visib;
  songNumber = getRandomNum(0, songs.length - 1);
  newMusic = songs[songNumber].tuneFile;
  msgVis.visibility = invib;
}


function setTrack()
{
  makeSongs();
  getSong();
  play();
}


function display(song,artist) 
{
  showSongArtist(song,artist);
}
  

function stopp() 
{
  stoppressed=true;
  paused = true;
  //alert(document.jukebox.isplaying());
  if (document.all) {
  	document.jukebox.stop();
  } else {
  	midiPlayer.innerHTML = "";
  }
  playing = false;
  display('','');
  resetstartTime();
  stopTimer();
  
  //recomecaID = setTimeout('recomeca()', tRecomeca); //teste

}

function mute() 
{
  if (!stoppressed) {
    recomecaID = setTimeout('recomeca()', tRecomeca); //teste
    estavatocando=playing;
    paused = true;
	  if (document.all) {
		document.jukebox.stop();
	  } else {
		midiPlayer.innerHTML = "";
	  }
    playing = false;
    display('','');
    resetstartTime();
    stopTimer();
  }
}

function unmute()
{
  if (!stoppressed) {
    play();
  }
  clearTimeout(recomecaID); //teste
}

function recomeca()
{
  if (!playing && newWin.closed) {unmute();} //teste if (!playing){&& newWin.closed	
  else {recomecaID = setTimeout('recomeca()', tRecomeca);} //teste
}


function checkMapaBlur()
{
  //window.parent.frames["erappspace"].setMapaFocus();
}


function play() 
{
  var t;
  stoppressed=false;
  if (paused)
  {
    paused = false;
    scrollSpeed = 200;
  }
  

//  if (document.all) 
//  {midiPlayer.innerHTML = "<EMBED SRC='" + newMusic + "' name='jukebox' id='jukebox' width='1' height='1' MASTERSOUND></Embed>";}

  if (document.layers) {
	  document.midiPlayer.document.write("<EMBED SRC='" + newMusic + "' name='jukebox' width='1' height='1' MASTERSOUND></Embed>");
  } else {
	  midiPlayer.innerHTML = "<EMBED SRC='" + newMusic + "' name='jukebox' width='1' height='1' MASTERSOUND></Embed>";
  }

  display(songs[songNumber].tuneName,songs[songNumber].tuneArtist);
  playing = true;
  resetstartTime();
  startTimer();
//  if (!firstsong) 
// {
//    t = setTimeout('checkMapaBlur()', 1000);
//  }
  firstsong = false;  
  //clearTimeout(recomecaID); //teste

}


function next()
{

  if (paused)
  {
    paused = false;
    scrollSpeed = 200;
  }

  stopp();
  ns = songNumber;
  getSong();
  if (songNumber == ns) {getSong();}
  play();
}  


function scrollMarquee() 
{
  window.setTimeout('scrollMarquee()', scrollSpeed);
  var msg = document.scrollform.box.value;
  document.scrollform.box.value = msg.substring(scrollChars) + msg.substring(0, scrollChars);
}


function showSongArtist(song,artist)
{
  scrollform.box.value = "";
  if (song.length > 0)
  {
    songName = song + " - " + artist + " - "; 
    //var songCompr = songName.length;
    if (songName.length < 40) {songName = songName + songName;} 
    if (songName.length < 40) {songName = songName + songName;} 
    scrollform.box.value = songName;
  }
}

-->
