function execute(command) {
  command = command.replace(/(^\s*|\s*$)/g, '');
  if(!command) return;

  var lut = {
      'g': 'http://www.google.com/search?q=%s',
    'gim': 'http://images.google.com/images?q=%s',
   'gmap': 'http://maps.google.com/maps?oi=map&q=%s',
   'gfin': 'http://finance.google.com/finance?q=%s',
     'yt': 'http://www.youtube.com/results?search_type=search_videos&search_sort=relevance&search_query=%s&search=Search',

    'tws': 'http://search.twitter.com/search?q=%s',

     'am': 'http://www.amazon.com/exec/obidos/external-search?mode=blended&keyword=%s',
  'am.ca': 'http://www.amazon.ca/exec/obidos/external-search?mode=blended&keyword=%s',
   'isbn': 'http://isbn.nu/%s',

  'td.ca': 'http://www.tigerdirect.ca/applications/SearchTools/search.asp?keywords=%s',
  'ne.ca': 'http://www.newegg.ca/Product/ProductList.aspx?Submit=ENE&Description=%s',

    'ann': 'http://www.animenewsnetwork.com/encyclopedia/search.php?searchbox=%s',
  'anidb': 'http://anidb.info/perl-bin/animedb.pl?adb.search=%s&show=animelist',
    'tot': 'http://www.tokyotosho.info/search.php?terms=%s',
    'tpb': 'http://thepiratebay.org/search/%s/0/7/0',
   'imdb': 'http://imdb.com/find?q=%s',

     'wp': 'http://en.wikipedia.org/?search=%s',
     'ud': 'http://www.urbandictionary.com/define.php?term=%s',
     'ed': 'http://encyclopediadramatica.com/?search=%s',

    'yim': 'http://images.search.yahoo.com/search/images?p=%s',
    'yfi': 'http://finance.yahoo.com/q?s=%s',
     'fl': 'http://flickr.com/photos/tags/%s',

     'gh': 'http://github.com/search?q=%s',
     'ls': 'http://yubnub.org/kernel/ls?args=%s'
  };

  var site = command.split(' ')[0];
  var query = command.split(' ').slice(1).join(' ');

  if(!lut[site]) {
    site = 'g';
    query = command;
  }

  if(!query) return;

  var dest = lut[site].replace(/%s/, encodeURI(query));

  if(!dest) return;

  return dest;
}

$(document).ready(function() {
  $('#command_input').focus();
  $('#command_form').submit(function() {
    dest = execute($('#command_input').val());
    if(dest) location = dest;

    return false;
  });
  $('#content a#links_toggler').click(function() {
    $('div#links').fadeIn("slow");
    return false;
  });
  $(document).bind('keydown', 'esc', function() {
    $('div#links').fadeIn("slow");
  });
});

