/* This file retrieved from the JS-Examples archives http://www.js-examples.com */
/*           PreLoaded Sounds Play on Mouseover                                 */
/*           Author Name:	JS-Examples                                     */
/*           Date Submitted:	February, 2002                                  */
/*           Runs in IE:	Yes                                             */
/*           Runs in NS:	Yes (claimed, but not confirmed - Sergey)       */

/* Browser-Sniffer */
/*
var isIE4 = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? true:false;
var isNS4 = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? true:false;
var isDOM = document.getElementById?true:false;
var isOK = isIE4||isNS4||isDOM;
 */

var Sounds = new Array();
var _s=0; /* just a counter - must start at 0 - do not change */

document.write('<BGSOUND ID="soundContainer_IE_DOM">');

onload=PreLoadSounds; /* this will make the pre-loading occur - put in body tag onload="PreLoadMusic()" if you want */


/* ------------------------------------------------------------------------ */
function preload_snd(snd_file) {
    Sounds[_s++] = snd_file;
}


/* ------------------------------------------------------------------------ */
function PreLoadSounds()
{
  if ( browser_old() ) return;

  /*
   * This block creates a container-object to hold all the hidden pre-loaded sound objects.
   */
	if ( browser_ie() ) {
    document.body.insertAdjacentHTML("BeforeEnd","<DIV ID='SoundDiv' STYLE='position:absolute;'></DIV>");
	}
	else if ( browser_ns4() && navigator.plugins["LiveAudio"] ) {
    SoundDiv = new Layer(0,window);
	}
  else if (browser_ns6() ) {
		objectInsertAdjacentHTML("BeforeEnd","<DIV ID='SoundDiv' STYLE='position:absolute;'></DIV>");
    if(document.implementation
        && document.implementation.hasFeature
        && document.implementation.hasFeature("HTML",""))
   	 HTMLElement.prototype.insertAdjacentHTML = objectInsertAdjacentHTML;
	}

  /*
   * This block writes all the sound objects into the container-object.
   */
  var Str = '';
  for (i=0;i<Sounds.length;i++)
    Str += "<EMBED SRC='"+Sounds[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"

	if ( browser_ie() ) {
    SoundDiv.innerHTML=Str;
	}
	else if( browser_ns6() ) {
    document.getElementById("SoundDiv").innerHTML=Str;
	}
  else if (browser_ns4() && navigator.plugins["LiveAudio"] ) {
    SoundDiv.document.open();
    SoundDiv.document.write(Str);
    SoundDiv.document.close();
  }

  /*
   * This finds the object -- we want to set an access method to make it play or stop.
   */
  soundObject = null;
	if ( browser_ie() ) {
    soundObject = document.all.soundContainer_IE_DOM;
	}
	else if( browser_ns6() ) {
    soundObject = document.getElementById('soundContainer_IE_DOM');
	}
  else if (browser_ns4() && navigator.plugins["LiveAudio"] ) {
    soundObject = SoundDiv;
    soundObject.control = auCtrl;
	}
  soundObject.control = auCtrl;
}

/* ------------------------------------------------------------------------ */
function auCtrl(SoundsArrayIndex,play)
{
  if (browser_ie() || browser_ns6() )
    this.src = play? Sounds[SoundsArrayIndex]:'';
  else if ( browser_ns4() && navigator.plugins["LiveAudio"] )
    eval("this.document.embeds[SoundsArrayIndex]." + (play? "play()":"stop()"))
}



/* ------------------------------------------------------------------------ */
function playSound(SoundsArrayIndex) { if (window.soundObject) soundObject.control(SoundsArrayIndex,true); }



/* ------------------------------------------------------------------------ */
function stopSound(SoundsArrayIndex) { if (window.soundObject) soundObject.control(SoundsArrayIndex,false); }


/* ------------------------------------------------------------------------ */
function objectInsertAdjacentHTML(where, str) {
	if ( !browser_ns6() ) return;

	var ihtml = this.innerHTML;

 	switch(where.toLowerCase()){
 		case "beforeend" :
 			ihtml += str;
 			break;
 		case "afterbegin" :
 			ihtml = str + ihtml;
 			break;
 		case "beforebegin":
 			var newHTML, range = document.createRange();
 			range.selectNode(this);
 			newHTML = range.createContextualFragment(str+this.innerHTML);
 			this.parentNode.replaceChild(newHTML, this);
 			break;
 		case "afterend":
 			var newHTML, range = document.createRange();
 			range.selectNode(this);
 			newHTML = range.createContextualFragment(this.innerHTML+str);
 			this.parentNode.replaceChild(newHTML, this);
 			break;
 	}
 	this.innerHTML = ihtml;
 }



