var xmlHttp //this object carries the request to the server,
//and carries the response back from the server.

function getBlurb(str) {
// 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    } 
    var url="music/getblurb.asp";
    url+="?q="+str;
    url+="&sid=" + Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function stateChanged()
// When Ajax is called, the result string is sent back to the div named "rightbar".
{
    if (xmlHttp.readyState == 4) {
        document.getElementById("blurb").innerHTML = xmlHttp.responseText;
    } 
}

function GetXmlHttpObject()
// When xmlHttp is called, have it be the object that's appropriate for the browser
{
  var xmlHttp=null;
  try {
  // Firefox, Opera 8.0+, Safari, Chrome
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) {
  // Internet Explorer, 6, and 7 or 8
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  } }
  return xmlHttp;
}

function embedAudio(songname) {  // Set to play in any of the browsers. 
    var objTag = '<p><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
    objTag += 'codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="120" height="100"> ';
	objTag += '    <param name="src" value="music/' + songname + '.mp3" /> ';
	objTag += '    <param name="controller" value="true" /> ';
	objTag += '    <param name="autoplay" value="true" /> ';
	objTag += '    <param name="autostart" value="true" /> ';
	objTag += '    <param name="pluginspage" value="http://www.apple.com/quicktime/download/" /> ';
	objTag += '<!--[if !IE]> <--> ';
	objTag += '    <object type="audio/x-mpeg" data="music/' + songname + '.mp3" width="120" height="100" autoplay="true"> ';
	objTag += '        <param name="src" value="music/' + songname + '.mp3" /> ';
	objTag += '        <param name="controller" value="true" /> ';
	objTag += '        <param name="standby" value="Loading..." /> ';
	objTag += '        <param name="autoplay" value="true" /> ';
	objTag += '        <param name="autostart" value="true" /> ';
	objTag += '        <param name="pluginurl" value="http://www.apple.com/quicktime/download/" /> ';
	objTag += '    </object>';
	objTag += '<!--> <![endif]--> ';
	objTag += '</object></p>';
	return objTag;
}

function playsong(songname) {
    document.getElementById("blurb").innerHTML = "";
    //document.getElementById("rightbar").innerHTML = "";
    document.getElementById("player").innerHTML = "";
    var theSong;
    var thePlayer;

    switch (songname) {
        case "jellyfish":
            getBlurb(songname);
            thePlayer = '<object  width="200" height="160"><param name="movie" value="http://www.youtube.com/v/UKeSFwIhl-I&autoplay=1">';
            thePlayer += '<param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always">';
            thePlayer += '<embed src="http://www.youtube.com/v/UKeSFwIhl-I&autoplay=1" type="application/x-shockwave-flash" ';
            thePlayer += 'allowfullscreen="true" allowScriptAccess="always" width="200" height="160"></object></br>';
            document.getElementById("player").innerHTML = thePlayer;
            return true;
            break;
        case "interlife":
            getBlurb(songname);
            thePlayer = '<object  width="200" height="160"><param name="movie" value="http://www.youtube.com/v/POotP7ssW4E&hl=en_US&fs=1&autoplay=1">';
            thePlayer += '<param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always">';
            thePlayer += '<embed src="http://www.youtube.com/v/POotP7ssW4E&hl=en_US&fs=1&autoplay=1" type="application/x-shockwave-flash" ';
            thePlayer += 'allowfullscreen="true" allowScriptAccess="always" width="200" height="160"></object></br>';
            document.getElementById("player").innerHTML = thePlayer;
            return true;
            break;
        default:
            getBlurb(songname);
            document.getElementById("player").innerHTML = embedAudio(songname); 

    }
}

