
var IE = false;
var InternetExploder = navigator.appVersion.indexOf("MSIE") != -1;
//var Mozilla = navigator.appName == "Netscape";
var Mozilla = true;

var sndDebug = false;
var sndURIByID = new Array();

function sndInline(uri, loop)
{
    if (IE)
    {
        // in IE loops have gaps if you use EMBED
        html = '<bgsound src="'+uri+'" '+(loop ? 'loop="infinite">' : '')+'</bgsound>';
    }
    else if (Mozilla)
    {
        html = '<embed hidden="true" MASTERSOUND src="'+uri+'" '+(loop ? 'loop="true"' : '') + ' autostart="true"></embed>';
    }
    document.write( html);
}

function sndDeclare(id, uri, loop)
{
    sndURIByID[id] = uri;
    if (IE && loop)
    {
        // in IE loops have gaps if you use EMBED
        html = '<bgsound id="snd_'+id+'" src="'+uri+'" '+(loop ? 'loop="infinite">' : '')+'</bgsound>';
    }
    else if (Mozilla || IE)
    {
        html = '<embed hidden="true" MASTERSOUND id="snd_'+id+'" src="'+uri+'" '+(loop ? 'loop="true" autostart="true"' : 'autostart="false"')+'></embed>';
    }

    if (sndDebug)
    {
        alert( html);
    }
    document.write( html);
}

function dump(o)
{
    var res = "";
    for (k in o)
    {
        if (o[k] != null)
        {
            res += k+" = "+o[k]+"; ";
        }
    }
    return res;
}

// Get the DOM element for the sound object
function sndGetElement(id)
{
    return document.getElementById("snd_"+id);
}

// Stop a sound by sound id
function sndStop(id)
{
    elem = sndGetElement(id);
    tag = elem.nodeName.toLowerCase();
    if (IE && (tag == "bgsound"))
    {
        elem.src = ''; // Null the src to stop it.
    }
    else
    {
        //alert( "embed stop: "+dump(elem));
        elem.stop();
    }
}

// Start a sound by sound id
function sndPlay(id)
{
    elem = sndGetElement(id);
    tag = elem.nodeName.toLowerCase();
    if (IE && (tag == "bgsound"))
    {
        elem.src = sndURIByID[id]; // re-instate the src to kickstart it
    }
    else
    {
        //alert( "embed play: "+dump(elem));
        elem.play();
    }
}
