/* 
  pacer.resource.org .js helpers and initialization
  requires MooTools 1.11
*/

/* show/hide the element with id */
function showhide(id) {
  if ($(id).style.visibility == "visible")
    return hide(id);
  else
    return show(id);
}

function show(id) {
  // No Fx version: $(id).style.visibility = "visible";
  new Fx.Style($(id), 'opacity').set(1);
  return false;
}

function hide(id) {
  new Fx.Style($(id), 'opacity', { duration: 500, fps: 20 }).start(0);
  return false;
}

/* "Amount Saved" class */
function PacerAmount()
{
  this.saved = $('amount_saved');
  this.orig = this.saved.innerHTML;

  /* update */
  this.update = function () {
    new Json.Remote('/current.php', {
      method: 'get',
      onComplete: function(amount) 
        {
          a = $('amount_saved');
          if (a.innerHTML != amount) {
            a.style.color = "#c00";
            a.innerHTML = amount;
          }
        }
    }).send();
  }

  /* return to original color */
  this.reset = function () {
    if (this.orig != this.saved.innerHTML) {
      this.saved.style.color = "#c00";
      this.orig = this.saved.innerHTML;
      new Fx.Style(this.saved, 'color', { duration: 4000 }).start('#666');
    }
  }

  this.poll = function () {
    this.update();
    this.reset.delay(2000,this);
  }
}

/* change soundManager2 defaults */
soundManager.debugMode = false;
soundManager.useConsole = false;
soundManager.consoleOnly = false;
soundManager.nullURL = '/snd/null.mp3'
function playrnd() {
  rnd = $random(1,21);
  id = 'sn'+rnd;
  soundManager.play(id, '/snd/'+rnd+'.mp3');
}

/* initialize */
window.addEvent('load', function()
{
  $$('a.control').each(function(clink){ clink.href = 'javascript:void(null);'; });
});
