var Sound = new (function() {

  this.mute = false;
  var loaded = false;
  var toLoad = [];

  function getFlashMovie() {
    return $("sound");
  }

  this.loadAll = function() {
    var str = "logon logoff new_chat_panel chat";
    if (typeof Game != "undefined") {
      str += " new_player turn shuffle in_hand leave_game card_played virtual_good";
    }
    $w(str).each(function(s) {
      this.load(s, "/media/general_" + s + ".mp3");
    }, this);
  };

  this.load = function(soundName, path) {
    if (loaded) {
      try {
        getFlashMovie().loadSound(soundName, path);
      } catch(e) {}
    } else {
      toLoad.push([soundName, path]);
    }
  };

  this.play = function(soundName) {
    if (this.mute) { return; }
    try {
      getFlashMovie().playSound(soundName);
    } catch(e) {}
  };

  this.finishedLoading = function() {
    loaded = true;
    toLoad.each(function(t) {
      this.load(t[0], t[1]);
    }, this);
  };

})();

Event.observe(window, 'load', function() { 
  Sound.finishedLoading.bind(Sound).delay(1); // Typically this should be fired when the flash object reports it has loaded
});
