CmdUtils.CreateCommand({
  name: "ktzr",
  icon: "http://ktzr.us/favicon.ico",
  homepage: "http://ktzr.us",
  author: { name: "Matt Langston", email: "matt@mavrev.com"},
  license: "GPL",
  description: "Shortens the selected URL using ktzr.us * מקצר כתובות באמצעות קצרוס",
  help: "ktzr <long url>",
  takes: {"longurl": noun_arb_text},
  preview: function( pblock, lurl ) {
       pblock.innerHTML = "Replaces the selected URL with a short URL";
       this._shorturl(pblock,lurl,"preview");
  },
  execute: function(lurl) {
    this._shorturl("",lurl,"execute");
  },
  
  _shorturl: function( pblock,lurl,call){
    var baseUrl = "http://ktzr.us/api.php";
    var params = {url: lurl.text};
    jQuery.get( baseUrl, params,function(sUrl){
      if (call=="preview"){
        pblock.innerHTML = "Replaces the selected URL with "+sUrl;
      }
      if (call=="execute"){
        CmdUtils.setSelection(sUrl);
        CmdUtils.copyToClipboard(sUrl);
      }
    })
    
  }
  
});CmdUtils.CreateCommand({
  name: "urlShort",
  icon: "http://mavrev.com/img/u/favicon.ico",
  homepage: "http://u.mavrev.com",
  author: { name: "Matt Langston", email: "matt@mavrev.com"},
  license: "GPL",
  description: "Shortens the selected URL using urlShort",
  help: "u<long url>",
  takes: {"longurl": noun_arb_text},
  preview: function( pblock, lurl ) {
       pblock.innerHTML = "Replaces the selected URL with a short URL";
       this._shorturl(pblock,lurl,"preview");
  },
  execute: function(lurl) {
    this._shorturl("",lurl,"execute");
  },
  
  _shorturl: function( pblock,lurl,call){
    var baseUrl = "http://u.mavrev.com/api.php";
    var params = {url: lurl.text};
    jQuery.get( baseUrl, params,function(sUrl){
      if (call=="preview"){
        pblock.innerHTML = "Replaces the selected URL with "+sUrl;
      }
      if (call=="execute"){
        CmdUtils.setSelection(sUrl);
        CmdUtils.copyToClipboard(sUrl);
      }
    })
    
  }
  
});
