CmdUtils.CreateCommand({
  name: "idek",
      
  takes: {"url to shorten": noun_arb_text},
  //preview: "Replaces the highlighted url with and ideked version",
  preview: function( pblock, longUrl ) {
      if(longUrl.text){
        url = longUrl.text;
        addtl = "If you have a url highlighted it will replace that url with the idek one.";
      }else{url = "the url you paste or type now"; addtl="";}
      pblock.innerHTML = "Places an ideked version of \'"+ url +"\' at your cursor. "+addtl;
      },
  execute: function( longUrl ) {
    var baseUrl = "http://idek.net/shorten/";
    var params = {'idek-api': "true", 'idek-url': longUrl.text};
    jQuery.get( baseUrl, params, function( result ) {
		CmdUtils.setSelection( result );
    })
  }
})

CmdUtils.CreateCommand({
  name: "idek-resolver",
 
  takes: {"idek link": noun_arb_text},
  preview: function( pblock, urlToShorten ) {
      if(urlToShorten.text.length >= 15 && urlToShorten.text.indexOf("http://") != -1){url = urlToShorten.text;}
      else{url = "the idek url you paste or type now"; }
      pblock.innerHTML = "Places the destination url of \'"+ url +"\' at your cursor.";
      },
  execute: function( shortUrl ) {
      // We need to get just the short (after the forward slash)
      if(shortUrl.text.length <= 14 || shortUrl.text.indexOf("idek.net") == -1){
         displayMessage("Sorry, you need to highlight an idek url first");
      }else{
         // search after "http://"
         var short = shortUrl.text.substr(shortUrl.text.indexOf("\/",8)+1);
         var baseUrl = "http://idek.net/"+ short +"?idek-api=true";
         jQuery.get( baseUrl, function( result ) {
            CmdUtils.setSelection( "<a href='"+ result +"'>"+ result +"</a>");
         })
      }
  }
})

