// The music of the body scripts.

function DrawMBButtons(n,btarg,rtarg,anim)
{
// Draw the nav buttons.
var j;
if (anim)
document.write('<div class="logopos"><a href="javascript:ClickButton('+"'"+'../index.htm'+"'"+')"><img src="images/MMusic_logo_main_pages_test.gif" width="154" height="111" border=0></a></div>');
else
document.write('<div class="logopos"><a href="javascript:ClickButton('+"'"+'../index.htm'+"'"+')"><img src="images/MMusic_logo_main_pages.gif" width="154" height="111" border=0></a></div>');

document.write('<div class="MMLt"><a href="javascript:ClickButton('+"'"+'../index.htm'+"'"+')"><img border=0 src="images/MMusic_text_logo.jpg" width="110" height="49"></a></div>');
document.write('<div class="MMLtb"><a href="javascript:ClickButton('+"'"+'index.htm'+"'"+')"><img border=0 src="images/Restart_button.jpg" width="118" height="44" OnMouseOver="Hi() "OnMouseOut="Lo()"></a></div>');
document.write('<div class="motbpos"><a href="javascript:ClickButton('+"'ltyb.htm?"+queryflags()+"&'"+')"><img border=0 src="images/NAV_B_Music_of_the_body_ON.jpg"                                   width="179" height="179"><br><div class="Up7">Music of the body</div></a></div>');
document.write('<div class="appos"><a href="javascript:ClickButton('+"'wiapm-1.htm?"+queryflags()+"&'"+')"><img border=0 src="images/NAV_B_About_proteins.jpg" OnMouseOver="Hi()" OnMouseOut="Lo()" width="179" height="179"><div class="Up7">About&nbsp;proteins</div></a></div>');

if (rtarg)
  {
  document.write('<div class="replaypos"><a href="javascript:Replay()"><img border=0 id="replay" src="images/NAV_Replay.jpg" OnMouseOver="Hi() "OnMouseOut="Lo()" width="105" height="105"><br><div style="position:relative;top:-7px;">Replay</div></a></div>');
  }

if (btarg!="")
  {
  document.write('<div class="backpos" ><a href="javascript:ClickButton('+"'"+btarg+"?"+querystring()+"'"+')"><img border=0 src="images/NAV_Back.jpg" OnMouseOver="Hi()" OnMouseOut="Lo()" width="105" height="105"><br>Back</a></div>');
  }

for (i=0;i<Math.floor(mbbuttons.length/3);i++)
  {
  j=i*3;
//  document.write('<div class="mb'+i+'pos"><a href="javascript:'+((i!=n-1)?'ClickButton('+"'"+mbbuttons[j+1]+"?"+querystring()+"'"+')':'')+'"><img border=0 src="images/'+mbbuttons[j]+'.jpg" '+((i!=n-1)?('OnMouseOver="Hi() "OnMouseOut="Lo()"'):'')+' width="105" height="105"><br><div style="position:relative;top:-7px;">'+mbbuttons[j+2]+'</div></a></div>');
  document.write('<div class="mb'+i+'pos"><a href="javascript:'+((i!=n-1)?'ClickButton('+"'"+mbbuttons[j+1]+"?"+querystring()+"'"+')':'')+'"><img border=0 src="images/'+mbbuttons[j]+'.jpg" '+((i!=n-1)?('OnMouseOver="Hi() "OnMouseOut="Lo()"'):'')+' width="105" height="105"><br>'+mbbuttons[j+2]+'</a></div>');
  }
}


var onobj,mto=null;

function Replay()
// Start the music and video again.
{
if (lock)
  return;

lock=true

onobj=replay;

onobj.src=TurnOn(onobj.src)
setTimeout("offobj()",500)
atomcnt=atommax+1;
}

function offobj()
// Turn it off again.
{
onobj.src=TurnOff(onobj.src)
lock=false
}

function LoadKoan()
{
var t=""

t=KoanAX.KoanGetNewFoundFiles()

if ((t==null) || (t==""))
  {
  setTimeout("LoadKoan()",20)
  }
else
  {
  KoanAX.KoanStop();
  InitVoices();
  KoanAX.KoanPlay();
  if (queryflags().indexOf("chime")>=0)
    doflash();
  setTimeout("MusicTick()",AVSyncTime);
  }
}

function MusicTick()
{
t=atomtime;
if (atomcnt>atommax)
  {
  if (queryflags().indexOf("koan")>=0)
    {
    KoanAX.KoanStop();
    atomcnt=1;
    KoanAX.KoanPlay();
    t=AVSyncTime;
    }
  }
if (queryflags().indexOf("chime")>=0)
  doflash();
setTimeout("MusicTick()",t)
}


// Functions to call when the body of the html page is loaded ...
function MyOnLoad()
{
if (queryflags().indexOf("koan")>=0)
  {
  KoanAX.KoanFileSet(GStartWithPiece)
  LoadKoan()
  }
else MusicTick();
SetPageTimeout()
}

function MyOnUnLoad()
{
if (queryflags().indexOf("koan")>=0)
  {
//  KoanAX.KoanVolumeLevel = 127
  KoanAX.KoanStop()
  }
}

function barToggle(c)
{
var m="m",s=""

eval("m=cmb["+c+"]");

m=!m

eval("cmb["+c+"]=m");


s="images/Compose_music_bar"+((!m)?"":"_ON")+".gif"

if (document.layers)
  {
  document.layers["bar"+c].background.src=path+s;
  }
else
  {
  document.all["bar"+c].style.background="url("+s+")";
  };
  

if (queryflags().indexOf("koan")>=0)
  {
  
  m=(!m)?"m":"/";
  
switch (c)
{
case 0: SetVoice1(m);
		  break;
case 1: SetVoice2(m);
		  break;
case 2: SetVoice3(m);
		  break;
case 3: SetVoice4(m);
		  break;
case 4: SetVoice5(m);
		  break;
case 5: SetVoice6(m);
		  break;
default:  break;
}
}
ReSetPageTimeout();
}

function DrawComposeBars(arr)
// Draw the composition bars table.
{
document.write("<table><tr><td>Hello Steve</td><tr></table>");
}

{
//for (i=0;i<arr.length;i++)
//  {
//  document.write('<tr><td id="bar'+i+'" class="musbar" background="images/Compose_music_bar'+(i==0?"_ON":"")+'.gif" valign="center" onClick="barToggle()"><img src="images/spacer.gif" width="15">'+arr[i]+'</td></tr>');
//  document.write('Hello<br>');
//  }
//  alert(i)
}
