﻿//Support function: checks to see if target element is an object or embed element
function IsObject(targetID)
{
    var isFound = false;
    var el = document.getElementById(targetID);
    if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED"))
    {
        isFound = true;
    }
    return isFound;
}

//Support function: creates an empty element to replace embedded SWF object
function ReplaceSwfWithEmptyDiv(targetID)
{
    var el = document.getElementById(targetID);
    if(el)
    {
        var div = document.createElement("div");
        el.parentNode.insertBefore(div, el);
        //Remove the SWF
        swfobject.removeSWF(targetID);
        //Give the new DIV the old element's ID
        div.setAttribute("id", targetID);
    }
}

function LoadMusic(music)
{
    //Check for existing SWF
    if(IsObject("audioPlayer"))
    {
        //replace object/element with a new div
        ReplaceSwfWithEmptyDiv("audioPlayer");
    }
    //Embed SWF
    flashvars.audio = music;
    flashvars.autoplay = "true";
    swfobject.embedSWF("flashaudioplayer.swf", "audioPlayer", "200", "35", "9.0.28", "expressInstall.swf", flashvars, params, attributes);
}
        
function DownloadMusic(music)
{
    if(IsObject("audioPlayer"))
    {
        //replace object/element with a new div
        ReplaceSwfWithEmptyDiv("audioPlayer");
    }
    window.location.href = "audios/"+music;
}