﻿// JScript File

var ie = (document.all) ? true : false; 
var _File;

function PlayObjW3CDOM(file){

	StopObjW3CDOM();
    if (_File != file) {
    
        if(ie){

		    var docfrag=document.createDocumentFragment();
    		
		    var myObj=document.createElement("OBJECT");
		    myObj.setAttribute("id", "objPlayer");
		    myObj.setAttribute("classid", "CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95");
		    myObj.setAttribute("codebase", "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701");		
		    myObj.setAttribute("FileName", file);
		    myObj.setAttribute("ShowControls", "False");
		    myObj.setAttribute("AutoStart", "True");
		    myObj.setAttribute("width", "0");
		    myObj.setAttribute("height", "0");

		    docfrag.appendChild(myObj);
		    document.getElementById('divSonido').appendChild(docfrag)
            _File = file;
            
	    }else{
    		
		    var docfrag=document.createDocumentFragment();
    	
		    var myEmbed=document.createElement("EMBED");
		    myEmbed.setAttribute("NAME", "FileName");
		    myEmbed.setAttribute("type", "application/x-mplayer2");
		    myEmbed.setAttribute("pluginspage", "http://www.microsoft.com/Windows/MediaPlayer/");
		    myEmbed.setAttribute("src", file);
		    myEmbed.setAttribute("id", "objPlayer");
		    myEmbed.setAttribute("autostart", "1");
		    myEmbed.setAttribute("ShowStatusBar", "false");
		    myEmbed.setAttribute("ShowControls", "true");
		    myEmbed.setAttribute("width", "0");
		    myEmbed.setAttribute("height", "0");
    		
		    var myObj=document.createElement("OBJECT");
		    myObj.setAttribute("id", "objPlayer");
		    myObj.setAttribute("classid", "CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95");
		    myObj.setAttribute("codebase", "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701");
		    myObj.setAttribute("width", "0");
		    myObj.setAttribute("height", "0");
    	
		    myObj.appendChild(myEmbed);
		    docfrag.appendChild(myObj);		    
		    document.getElementById('divSonido').appendChild(docfrag)
	    }    
    
    }else{
        _File = null;
    }
	
}

function StopObjW3CDOM(){ 
	if(document.getElementById("objPlayer")!=null){
		if(ie){document.getElementById("objPlayer").stop();}
		var objQuitar = document.getElementById("objPlayer");
		objQuitar.parentNode.removeChild(objQuitar); 
	}
}

function playSound(url) {

    PlayObjW3CDOM(url);

}

function stopSound(url) {

    StopObjW3CDOM();
}