CmdUtils.CreateCommand({
  name: "blip",
  takes: {"title": noun_arb_text},
  icon: "http://www.blippr.com/images/favicon.ico",
  author: {name: "Ben Coleman", email: "benc.uk@gmail.com"},
  license: "GPL",
  description: "Searches Blippr for books, games and movies",

  //////////////////////////////////////////////////////////////////////////////////

  preview: function(pblock, title) 
  {
    var apiUrl = "http://www.blippr.com/search/all.json?term="+title.text+"&page=1&api_key=e77fe7fcf1c3177cb09a78f221ad6a26";

    jQuery.ajax({
      type: "GET",
      url: apiUrl,
      datatype: "string",

      error: function() {
        previewBlock.innerHTML = "Error searching Blippr";
      },

      success: function(searchReponse) {
        searchReponse = Utils.decodeJson(searchReponse);

        var templ = "<table style='font-family: Arial'>{for t in titles}<tr><td align='middle'><a href='http://www.blippr.com/${t.media_type}/${t.id}'><img height='100' border='0' src='${t.image}'></a></td><td><a href='http://www.blippr.com/${t.media_type}/${t.id}'>${t.title}</a></td></tr>{/for}</table>";

        pblock.innerHTML = "Found " + searchReponse.search.query.total_results + " titles on Blippr:" + CmdUtils.renderTemplate( templ, {titles: searchReponse.search.results.result.splice(0, 4)} );
      }

    });

    pblock.innerHTML = "Lookup "+title.text+" on Blippr"
  },

  //////////////////////////////////////////////////////////////////////////////////

  execute: function( title ) {
    var searchUrl = "http://www.blippr.com/search";
    var searchParams = {term: title.text};
    Utils.openUrlInBrowser(searchUrl + Utils.paramsToString(searchParams));

  }
})
