makeSearchCommand({
  name: "google-book",
  homepage: "http://www.radiantweb.net/ubiquity/",
  author: { name: "Ian Cabell", email: "ian@radiantweb.net"},
  contributors: ["Ian Cabell"],
  license: "CC SA 3.0",
  description: "Search Google Books for your terms.",
  takes: {"search word(s)": noun_arb_text},
  baseurl: "http://ajax.googleapis.com/ajax/services/search/books",
  url: "http://books.google.com/books?q={QUERY}",
  icon: "http://books.google.com/favicon.ico",
  preview: function(pblock, directObject) {
    var searchTerm = directObject.text;
    pblock.innerHTML = CmdUtils.renderTemplate("Searches Google Books for <b>${query}</b>", {query: searchTerm});
    var params = { v: "1.0", q: searchTerm };
    var tpl = "<style>h2.resbdy{font-size:1.2em; margin:-0.1em 0 0 0;padding:0px; font-weight:normal; line-height:normal}</style>" +
"{for result in results}" +
"<table><tr><td valign=top><div class='casmall'><a href='../${result.url}'><img alt='${result.titleNoFormatting}' class='coverthumb' title='${result.titleNoFormatting}' src='../${result.tbUrl}' border=0 height=${result.tbHeight} width=${result.tbWidth}></a></div></td><td width=10>&nbsp;</td><td valign=top><h2 class='resbdy'><a href='../${result.url}'>${result.title}</a></h2><font size=-1><span style='line-height: 1.2em;'><span class=ln2>by ${result.authors} - ${result.pageCount} pages</span></span></font><br/></td></tr></table>" +
"{/for}";

    jQuery.get( this.baseurl, params, function(data) {
      var numToDisplay = 3;
      var results = data.responseData.results.splice( 0, numToDisplay );

      pblock.innerHTML = CmdUtils.renderTemplate( tpl,
						  {results:results}
						);
      }, "json");
  },
  execute: function(directObject) {
    Utils.openUrlInBrowser( this.url.replace( /{QUERY}/g, directObject.text) );
  }
});
