
function getMusic()
{
// Make a DIV to hold the player and place it off the screen
// so that we don't see it

  if (window.ActiveXObject)
  {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
  // code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation.createDocument)
  {
    xmlDoc=document.implementation.createDocument("","",null);  
  }
  else
  {
    alert('Your browser cannot handle this script');
  }

  xmlDoc.async=false;
  xmlDoc.load("music.xml");
  var root;
  var numFiles;
  var pos;
  var i;
  var randomNumber;
  var musicTitle;
  var playWMA;
  var name;

  root = xmlDoc.documentElement; // <music>
  numFiles = root.getElementsByTagName('title').length
  
  playWMA = detect_browser() == "MSIE" || detect_browser() == "Netscape";
  
  if (playWMA)
  {
    do
    {
      randomNumber = Math.floor(Math.random()* numFiles);
      musicTitle = "music/" + root.getElementsByTagName('file')[randomNumber].firstChild.nodeValue;
      name = root.getElementsByTagName('name')[randomNumber].firstChild.nodeValue;
    }
    while (musicTitle.indexOf(".mid",0) != -1);
  }
  else
  {
    do
    {
      randomNumber = Math.floor(Math.random()* numFiles);
      musicTitle = "music/" + root.getElementsByTagName('file')[randomNumber].firstChild.nodeValue;
      name = root.getElementsByTagName('name')[randomNumber].firstChild.nodeValue;
    }
    while (musicTitle.indexOf(".wma",0) != -1);
    document.write(name);
  }
   
//  document.write(name);
  document.write('<DIV ID="player"></DIV>');
  load(musicTitle);
}

function detect_browser()
{
var browser_name = navigator.userAgent;
// We have to check for Opera first because
// at the beginning of the userAgent variable
// Opera claims it is MSIE.

if (browser_name.indexOf("Opera")!= -1)
browser_name = "Opera";
else if (browser_name.indexOf("Firefox")!= -1)
browser_name = "Firefox";
else if (browser_name.indexOf("MSIE")!= -1)
browser_name = "MSIE";
else if (browser_name.indexOf("Netscape")!= -1)
browser_name = "Netscape";
else if (browser_name.indexOf("Safari")!= -1)
browser_name = "Safari";

return browser_name;

} // end function detect_browser()

function load(media)
{
var player = document.getElementById('player');

if (detect_browser() == "MSIE" ||
detect_browser() == "Netscape")
{
player.innerHTML = '<object id="sound"'
+ 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"'
+ 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"'
+ 'standby="Loading Microsoft® Windows® Media Player components..."'
+ 'type="application/x-oleobject" width="250" height="150">'
+ '<param name="url" value="'+media+'">'
+ '<param name="volume" value="50">'
+ '<embed id="sound" type="application/x-mplayer2" src="'+media+'"'
+ 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"'
+ 'pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"'
+ 'type="application/x-mplayer2"'
+ 'url="'+media+'"'
+ 'voume="50"'
+ 'width="250" height="150">'
+ '<\/embed>'
+ '<\/object>';
}
else // if Safari or Firefox, then load Quicktime controls
{
player.innerHTML = '<OBJECT '
+ 'CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '
+ 'WIDTH="200"HEIGHT="16" ID="sound"'
+ 'CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">'
+ '<PARAM name="SRC" VALUE="'+media+'">'
+ '<PARAM name="AUTOPLAY" VALUE="true">'
+ '<PARAM name="CONTROLLER" VALUE="false">'
+ '<PARAM name="VOLUME" VALUE="50">'
+ '<PARAM name="ENABLEJAVASCRIPT" VALUE="true">'
+ '<PARAM name="TYPE" VALUE="audio/wav">'
+ '<embed classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'
+ 'name="sound"'
+ 'id="sound"'
+ 'src="'+media+'"'
+ 'pluginspage="http://www.apple.com/quicktime/download/"'
+ 'volume="50"'
+ 'enablejavascript="true" '
+ 'type="audio/wav" '
+ 'height="16" '
+ 'width="200"'
+ 'autostart="true"'
+ '> </embed>'
+ '</OBJECT>';
}
} // end function load(media) 
