jQuery.do_once = function(identifier, fn){
  if (window.do_once == null) window.do_once = {};

  // if the identifier hasn't been used 
  // mark it as having been used and call 
  // the function
  if (window.do_once[identifier] == null) {
    window.do_once[identifier] = true;
    fn.call();
  }
}

jQuery.fn.do_once = function(identifier, fn) {
  return jQuery(jQuery.grep(this, function(element){

    // if this identifier has already been used 
    // on this element, do not return it
    if ( jQuery(element).data('do_once:' + identifier) != null ) {
      return false;

    // otherwise, mark this element as having been 
    // used by this identifier and return the element
    // also: call fn if one was passed
    } else {
      jQuery(element).data('do_once:' + identifier, true);
      if (fn != null) fn.apply(element);
      return true;
    }

  }));
}
