/*
Get info on a bit.ly link
*/
CmdUtils.CreateCommand({
  names: ["bitly-info"],
  icon: "http://bit.ly/static/images/favicon.png",
  description: "Get info on bit.ly links",
  help: "Highlight a bit.ly link.  The preview pane should show some bit.ly info and pressing enter will take you to the bit.ly info page.",
  author: {name: "Alex Beutel", email: "alex.beutel@gmail.com"},
  license: "GPL",
  homepage: "http://blog.ambmediadesign.com/",
  arguments: [{role: 'object', label: 'bit.ly address', nountype: noun_arb_text}],
  preview: function preview(pblock, args) {
    var self = this;
    var ar = args.object.text.split("/");
    var hash = ar[ar.length - 1];
    var url = "http://api.bit.ly/stats?version=2.0.1&shortUrl="+args.object.text+"&login=ambpublic&apiKey=R_ab4bccbd378ad4a647019ad9d36a3ca4 ";
    var prev = pblock;
    pblock.innerHTML = "Looking up info on  <b>" + args.object.text + "</b>.<br /> AJAX go!";
    $.ajax({
       type: "GET",
       url: url,
       async: true,
       dataType: 'json',
       success: function(json) {
			var clicks = json['results']['userClicks'];
			prev.innerHTML = clicks + " clicks so far.<br /><br />Press enter for more details.";
       }
    });
  },
  execute: function execute(args) {
    var ar = args.object.text.split("/");
    var hash = ar[ar.length - 1];
    Utils.openUrlInBrowser("http://bit.ly/info/" + hash);
  }
});
