     /**************************************************************************************************
		 *  This crossbrowser friendly sound code is (C) CopyRight Vidar Larsen 2005+ http://cyber-web.biz  *
     **************************************************************************************************/



//========================[Sound variables - checking for sound] ===================================//
var NSsound = navigator.plugins && navigator.plugins["LiveAudio"];  
var IEsound = navigator.plugins && document.all;		   						 
var audioEnabled = NSsound || IEsound;				  									



//========[crossbrowser init sound]==============//
function makeSoundDiv(soundname,newInnerHTML) {
    var oDiv = document.createElement ("DIV");
    oDiv.id = soundname;
	
 		oDiv.style.position = "absolute";
		oDiv.style.left=-2000;
    oDiv.innerHTML=newInnerHTML;
    document.body.appendChild (oDiv);
    delete oDiv; }
//==================================[crossbrowser init sound]========================================//
function init(soundfile,autostart,loopit) {
	
	soundname=soundfile;
	var buff='';
	if (loopit==null) loopit=false;
	if (audioEnabled) {
				
				if (autostart==null) autostart=false;
				buff+='<embed name="player" id="player" src='+soundfile+' autoplay="'+autostart+'" AUTOSTART="'+autostart+'" loop="'+loopit+'" hidden="true" volume="80%" > ';
				buff+='<NOEMBED><BGSOUND src='+soundfile+'></NOEMBED>';
			  buff+='</embed> ';
	} else { // try something else
			
			if (autostart==true) autostart=1; else autostart=0;
			if (loopit==true) loopit=1; else loopit=0;	
		
			buff+='<object type="application/x-mplayer2" name="player" id="player" ';
			buff+=' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ';
			buff+=' Name="obj_'+soundname+'" src='+soundfile+' AutoStart='+autostart+' ShowStatusBar=1 volume=-1 loop='+loopit+' >';
  		buff+=' </object> ';
	}
	if (!document.getElementById(soundname)) makeSoundDiv(soundname,"");
	if (!document.getElementById(soundname+"_buffer")) makeSoundDiv(soundname+"_buffer",buff);
	 else newContent(soundname+"_buffer",buff);
}

function newContent(layernm,content) { // crossbrowser and backward compatible
	if (document.getElementById) document.getElementById(layernm).innerHTML=content;
	else if (document.all) document.all[layernm].innerHTML=content;
	else if (document.layers) {					
		eval('  document.layers["'+layernm+'"].document.open();');			
		eval("  document.layers['"+layernm+"'].document.write('"+content+"');");     
		eval('  document.layers["'+layernm+'"].document.close();');		     
  } 
}



function play(soundname,loopit) {
	if (!document.getElementById(soundname) || document.getElementById(soundname+"_buffer").innerHTML=="") init(soundname,true,loopit);
	 else newContent(soundname,document.getElementById(soundname+"_buffer").innerHTML); 
	  
}

function stop(soundname) {
	//alert(document.getElementById(soundname+"_buffer").innerHTML);
	//alert(document.getElementById(soundname).innerHTML);
	if (document.getElementById(soundname)) soundDiv = document.getElementById(soundname).innerHTML;
	if (document.getElementById(soundname+"_buffer")) soundBuffer = document.getElementById(soundname+"_buffer").innerHTML;
	
	
	if (typeof soundDiv!="undefined" && soundDiv!="") newContent(soundname,"");
	 else if (typeof soundBuffer!="undefined") newContent(soundname+"_buffer","");
	  else document.title="[ERR] Layer does not exist : ["+soundname+"]";

	
}
