CmdUtils.CreateCommand({
  name: "count",
  icon: "chrome://ubiquity/skin/icons/sum.png",
  homepage: "http://mitcho.com/code/",
  author: { name: "mitcho (Michael Yoshitaka Erlewine)", email: "code@mitcho.com"},
  license: "GPL",
  description: "Count things on your page, like table rows, columns, links, etc.",
  help: "Select a section of your page and try <code>count tr in this</code> for table rows or <code>count a in this</code> for links. You can use <a href='http://docs.jquery.com/Selectors'>complex selectors</a> too.",
  takes: {"CSS selector": noun_arb_text },
  modifiers: {'in': noun_arb_text},
  preview: function( pblock, input, modifiers ) {
    var selector = modifiers.direct_object.text;
    var target = modifiers.in;
    // isEmpty function by Blair McBride
    var isEmpty = function(o) { for(p in o) return false; return true; };

    if (selector == '' || isEmpty(selector))
      return (pblock.innerHTML = 'You must specify a selector.');
    if (jQuery(target.html).length == 0 || isEmpty(target.html))
      return (pblock.innerHTML = 'You must select something.');

    var count = (jQuery('<div/>').append(jQuery(target.html).clone()).find(selector).length);
    pblock.innerHTML = 'Found '+count+' <code>'+selector+'</code> elements.';
    return 'Found '+count+' '+selector+' elements.';
  },
  execute: function(input,modifiers) {
    displayMessage(this.preview('',input,modifiers));
  }
});