
 // by Thomas Favennec ;-)

 function Play(id,file)
 {
   if(played)
   {
    if(file==played)
    {
     if(!pause)
     {
      pause=1;
      document.getElementById("song"+playedid).style.textDecoration="blink";
      soundManager.pause('mySound'+playedid);
     }
     else
     {
      soundManager.resume('mySound'+playedid);
      document.getElementById("song"+playedid).style.textDecoration="none";
      pause=0;
     }
    }
    else
    {
     soundManager.stopAll();
     //soundManager.destroySound('mySound');
     document.getElementById("song"+playedid).style.color="#FFF";
     document.getElementById("song"+playedid).style.fontSize="";
     document.getElementById("song"+playedid).style.textDecoration="none";
     document.getElementById("td"+playedid).innerHTML="";
    }
   }
   playedid=id;
   played=file;
   document.getElementById("song"+playedid).style.color="red";
   document.getElementById("song"+playedid).style.fontSize="20px";
   document.getElementById("td"+playedid).innerHTML='<div style="width:300px;border:2px solid #DDD;-moz-border-radius:5px;height:5px"><div id="m0" style="position:absolute;width:0px;height:5px;background-color:#DDD;"></div><div id="m" style="position:absolute;width:0px;height:5px;background-color:red;"></div></div>';
   if(!soundManager.getSoundById('mySound'+playedid))
   soundManager.createSound(
   {
    id: 'mySound'+playedid,
    url: 'mp3/'+file+'.mp3',
    autoLoad: true,
    autoPlay: true,
    onfinish: playAgain
   });
   else soundManager.getSoundById('mySound'+playedid).play();
 }



 function playAgain()
 {
   if(playedid<total-1) Play(playedid+1,thelist[playedid+1]);
 }


 function deamond()
 {
  if(played)
  {
   a=soundManager.getSoundById('mySound'+playedid);
   blastp=a.bytesLoaded;
   blastd=a.bytesTotal;

   if(!pause)
   {
     lastp=a.position;
     lastd=a.duration;
     laste=a.eqData;

     var gPixels = document.getElementById('equa').getElementsByTagName('div');
     var gScale = 32; // draw 0 to 32px from bottom
     var j=0;
     for (var i=0; i<128; i++) if(laste[i])
     {
      if(j) gPixels[i].style.backgroundColor="#FFF";
      else gPixels[i].style.backgroundColor="red";
      gPixels[i].style.height=parseFloat(laste[i])*100-i/2+'px';
      if(j) j=0; else j=1;
     }
     else gPixels[i].style.backgroundColor="";
   }

   if(blastp) document.getElementById("m0").style.width=blastp*300/blastd+"px";
   if(lastp) document.getElementById("m").style.width=lastp*(blastp*300/blastd)/lastd+"px";
   setTimeout("deamond()",80);
  }
 }


