// This is the onclick handler for a recommendation link.  It implements
// click-through tracking.
//
// Please see: http://kk.api.24hrdiner.com/api/documentation#click_through_tracking
function blueplateClickThrough(elem, options) {

  // Whether the beacon is available or not, go the URL the user clicked on.
  function go(event) {
    location.href = href;
  };

  options = options || {};
  var href = elem.href;
  var request_url = options.request_url || '';
  var beacon_url = 'http://kk.api.24hrdiner.com/api/beacon' +
                   '?request_url=' + escape(request_url) +
                   '&click_through_url=' + escape(href);

  var img = new Image();
  img.onload = go;
  img.onerror = go;
  img.src = beacon_url;

  // Avoid memory leaks caused by circular references.
  img = null;

  return false;
}
