//==================================================================================================
// S o u n d                                                                             JavaScript
//                                                                                By Bruno Bachelet
//==================================================================================================
// Copyright (c) 1999-2005
// Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net
//
// This program is free software; you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
// the GNU General Public License for more details (http://www.gnu.org).
//
// This file allows you to play a sound on Microsoft Internet Explorer and Mozilla browsers.
//
// 1) Include this code in your HTML page.
//    <script type="text/javascript" src="scripts/sound.js"></script>
//
// 2) Create your sound with JavaScript. You can create as many sounds as you want.
//    new Sound("my_sound","sounds/my_sound.wav");
//
// 3) Now, you can control your sound with JavaScript.
//    document.sounds["my_sound"].play(); // Plays the sound.
//    document.sounds["my_sound"].stop(); // Stops the sound.

var sounds = new Array;

function Sound(name,file) {
 var microsoft = (navigator.appName == "Microsoft Internet Explorer");
 var mozilla   = (navigator.appName == "Netscape");

 this.name = name;
 this.file = file;

 this.start = function () {
  if (microsoft) document.getElementById(this.name).src = this.file;
  else if (mozilla) {
   eval("document."+this.name).Rewind();
   eval("document."+this.name).Play();
  }
 }

 this.stop = function () {
  if (microsoft) document.getElementById(this.name).src = "";
  else if (mozilla) eval("document."+this.name).Stop();
 }

 this.insert = function() {
  if (microsoft) document.write("<bgsound id='"+this.name+"' src='' loop='65535'/>");
  else if (mozilla) {
   document.write("<embed id='"+this.name+"' src='"+this.file+"' ");
   document.write("width='100' height='100' autostart='false' loop='true'/>");
  }
 }

 this.insert();
 sounds[name] = this;
}

// End //-------------------------------------------------------------------------------------------

