CmdUtils.CreateCommand({
  name: 'sm00sh',
  icon: 'http://smsh.me/favicon.ico',
  homepage: "http://smsh.me/action/ubiquity",
  author: { name: "iPublicis Internet Agency", email: "ipublicis@gmail.com"},
  license: "GPL",
  description: "Shortens the selected URL using sm00sh at smsh.me",
  help: "sm00sh <long url>",
  takes: {"longurl": noun_arb_text},
  preview: function( pblock, lurl ) {
       pblock.innerHTML = "Replaces the inputted URL with a sm00sh URL.";
       this._shorturl(pblock,lurl,"preview");
  },
  execute: function(lurl) {
    this._shorturl("",lurl,"execute");
  },
  
  _shorturl: function( pblock,lurl,call){
    var baseUrl = "http://smsh.me/?key=5960c306a7ac1b465faf62b9a0cd2662b33d7111&api=json&url=";
    var params = {longurl: lurl.text};
    jQuery.get( baseUrl, params,function(sUrl){
      if (call=="preview"){
        pblock.innerHTML = "Replaces the selected URL with a shorten one."; // +sUrl;
      }
      if (call=="execute"){
        CmdUtils.setSelection(sUrl);
        CmdUtils.copyToClipboard(sUrl);
      }
    })
    
  }
  
});

