function copy_to_clipboard(thing) {
	// FROM: http://developer.mozilla.org/en/Using_the_Clipboard

	const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
	gClipboardHelper.copyString(thing);
	displayMessage(thing + " copied to the clipboard");
}

CmdUtils.CreateCommand({
  name: "zima",
  takes: {"url to shorten": noun_arb_text},
  icon: "http://zi.ma/favicon.png",
  locale: "en-US",
  homepage: "http://zi.ma",
  author: {name: "Martin Bowling", email: "martinbowling@gmail.com"},

  description: "Replaces the selected URL with a shortened version from <a href=\"http://Zi.ma/\">Zi.ma</a><br/>And copies it to your clipboard for further use",
  license: "MPL",    
  preview: function( pblock, urlToShorten ){
    pblock.innerHTML = "Replaces the selected URL with a shorted version (using zi.ma).";
      //var regexp = /(ftp|http|https):\/\/(\w+:{01}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
      var baseUrl = "http://zi.ma/?module=ShortURL&file=Add&mode=API&url=";
      pblock.innerHTML = "Replaces the selected URL with ",
      jQuery.get( baseUrl + urlToShorten.text, function( zima ) {
        if(zima != "Error") pblock.innerHTML += zima;
      });
  },
  execute: function( urlToShorten ) {
    var baseUrl = "http://zi.ma/?module=ShortURL&file=Add&mode=API&url=";
    jQuery.get( baseUrl + urlToShorten.text, function( zima ) {
      CmdUtils.setSelection( zima );
      //displayMessage("TDB: Copy this zi.ma to the clipboard => " + zima );
		copy_to_clipboard( zima );
    })
  }
});


