//
//  lyons-share.js
//

var flashAnimator;

function prepareFlashes () {
  var flash = $("flash")
  if (flash) {
    flash.setOpacity(0.0);
    flashAnimator = Animator.apply(flash, "opacity: 1.0");
    showFlash();
    setTimeout(hideFlash, 2000);
    Event.observe(flash, "click", function () {
      $("flash").hide();
    });
  }
}

function showFlash () {
  flashAnimator.seekTo(1.0);
}

function hideFlash () {
  Object.extend(flashAnimator.options, {
    onComplete: function () { $("flash").hide(); }
  });
  flashAnimator.seekTo(0.0);
}

function preparePlaceholders () {
  $$("input.placeholder").each(function (field) {
    field.originalValue = field.value;
    Event.observe(field, "focus", hidePlaceholderText);
    Event.observe(field, "blur",  showPlaceholderText);
  });
}

function hidePlaceholderText () {
  if (this.value == this.originalValue)
    this.value = "";
}

function showPlaceholderText () {
  if (this.value.strip() == "")
    this.value = this.originalValue;
}

Event.observe(window, "load", prepareFlashes);
Event.observe(window, "load", preparePlaceholders);

