ver=parseInt(navigator.appVersion)
ie4=(ver>3  && navigator.appName!="Netscape")?1:0
ns4=(ver>3  && navigator.appName=="Netscape")?1:0
ns3=(ver==3 && navigator.appName=="Netscape")?1:0
var prevSound;

function playSound(soundName) {
	if (navigator.appName == "Microsoft Internet Explorer"){
		document.all['BGSOUND_ID'].src="http://interface.audiovideoweb.com/lnk/avwebdsnjwebsrvr4503/"+soundName+"/play";
	}
	else
	{
		if (document.embedname)  {
			var oNodeToRemove = document.embedname;
			oNodeToRemove.parentNode.removeChild(oNodeToRemove);
		}
		var element = document.createElement("embed");
		element.setAttribute("src", "http://interface.audiovideoweb.com/lnk/avwebdsnjwebsrvr4503/"+soundName+"/play");
		element.setAttribute("name", "embedname");
		element.setAttribute("height", 0);
		element.setAttribute("width", 0);
		document.body.appendChild(element);
	}
}

function replaySound() {
  playSound(prevSound);
}

function stopSound() {
 if (ie4) document.all['BGSOUND_ID'].src='';
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
 )
 {
  document.getElementById("embAudio").stop()
 }
}

function openAudioWindow() {
if (height > 500) {
	height=800;
}
	var melodyStr = "";
/*
	if (/Mozilla\/5\.0/.test(navigator.userAgent)) {
		melodyStr = getInnerHTML(document.getElementById('music')) 
	} else {
		melodyStr = document.getElementById('music').innerHTML;
	}
*/
	melodyStr = document.getElementById('music').innerHTML;
	
	var playerStr = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" height=\"47\" width=\"100%\">";
	
	playerStr += "<tr><td valign='top' background=\"/lib/courtneyscandles/player-bg.gif\" style='padding-top:20px;padding-right:15px;'align='right'><table cellspacing=0 cellpadding=0 border=0><tr><td><a href='javascript:stopSound()'>Stop</a></td><td><a href='javascript:stopSound()'><img src='/lib/courtneyscandles/stop.gif' align='right' border=0></a></td></tr></table></td></tr></table>";
	
	var bodyStr = '<html><head><title>Listen</title>';
	bodyStr += '<style>TABLE {margin:10px 0px } TD {font:normal 11px arial;}</style>';
	bodyStr += '</head><body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0>';
	var bodyStrEnd = '</body></html>';
	var newWin = window.open('', 'audioWin', 'location=no,menubar=no,width='+width +',height='+height)
	newWin.document.write(bodyStr + melodyStr + playerStr + bodyStrEnd);
	//newWin.document.getElementById('music').style.display='block';
	//newWin.document.title='Listen - '+ document.title;
	newWin.focus();

}

function getInnerHTML(node) {
   var str = "";
   for (var i=0; i<node.childNodes.length; i++)
      str += getOuterHTML(node.childNodes.item(i));
   return str;
}
var _leafElems = ["IMG", "HR", "BR", "INPUT"];
var leafElems = {};
for (var i=0; i<_leafElems.length; i++)
   leafElems[_leafElems[i]] = true;

function getOuterHTML(node) {
   var str = "";

   switch (node.nodeType) {
      case 1: // ELEMENT_NODE
         str += "<" + node.nodeName;
         for (var i=0; i<node.attributes.length; i++) {
            if (node.attributes.item(i).nodeValue != null) {
               str += " "
               str += node.attributes.item(i).nodeName;
               str += "=\"";
               str += node.attributes.item(i).nodeValue;
               str += "\"";
            }
         }

         if (node.childNodes.length == 0 && leafElems[node.nodeName])
            str += ">";
         else {
            str += ">";
            str += getInnerHTML(node);
            str += "<" + node.nodeName + ">"
         }
         break;

      case 3:   //TEXT_NODE
         str += node.nodeValue;
         break;

      case 4: // CDATA_SECTION_NODE
         str += "<![CDATA[" + node.nodeValue + "]]>";
         break;

      case 5: // ENTITY_REFERENCE_NODE
         str += "&" + node.nodeName + ";"
         break;

      case 8: // COMMENT_NODE
         str += "<!--" + node.nodeValue + "-->"
         break;
   }

   return str;
}
