jQuery.fn.fadeToggle = function(speed, easing, callback) {
     return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

jQuery.fn.fadePulse = function(count, speed) {
  /* Why count - 1? Don't know but it seems to be right! */
  return this.effect("pulsate", { times: count - 1 }, speed);
};

function preload_img(url) {
    $('<img>').css('display', 'none').attr('src', url).appendTo($('body'));
}

$.fn.hopTo = function(n) {
  var inputs = $("input.hop, input.hoptgt", this.closest("form"));
  var whence = inputs.eq(inputs.index(this) + n);
  if (whence.length)
    whence.focus();
  return whence;
}

$.fn.hopBackward = function() {
  var where = this.hopTo(-1);
  if (where.length && where.is('input[type="text"]')) {
    where.caret(where.val().length);
  }
}

$.fn.hopForward = function(clear) {
  var where = this.hopTo(+1);
  if (where.length && where.is('input[type="text"]')) {
    if (clear) {
      where.val("");
    } else {
      where.caret(0);
    }
  }
}

function hop_keydown(e) {
  var bs = false;
  var left = false;
  if (e.keyCode == 8 && this.value.length == 0) { /* Backspace on empty field */
    bs = true;
  } else if (e.keyCode == 37 && $(this).caret() == 0) { /* Left arrow on the left edge of a field */
    left = true;
  } else if (e.keyCode == 39 && $(this).caret() == this.value.length) { /* Right arrow on the right edge */
    $(this).hopForward(0);
    return false;
  } else { /* Pass the event on, we don't recognize it */
    return true;
  }
  $(this).hopBackward();
  return bs;
  /* If it was a backspace, let the event percolate so a char gets deleted from the box
   * we just jumped back into. If it was a left-arrow then swallow the event so the cursor
   * doesn't move from where we wanted it.
   */
  return bs; 
}

function hop_keyup(e) {
  if (e.keyCode == 9 || e.keyCode == 16 || e.keyCode == 8 // Shift | Tab | Backspace
      || (e.keyCode >= 37 && e.keyCode <= 40)) { // arrow keys
    return true;
  }
  if (this.value.length < this.maxLength) {
    return true;
  } // Any other key, on a full field.
  $(this).hopForward(true);
  return true;
}

$(function() {
    $("input.hop").keyup(hop_keyup).keydown(hop_keydown);
    $('.fadeIn').hide().fadeIn(2000);
    }
);
