// Configuration: <div id='proto_heatmap_config' offset_element='.some-class' callback='http://heat.savvica.com/click.js' />
// offset-element: Used to determine the X offset from the left side of the viewport. Can be any css selector, if multiple elements are returned the first is used.
// callback: the URL that will record clicks. Passed three params (url, x, y)

ProtoHeatMap = {
  record_click : function(event) {
    var config = $('proto_heatmap_config');
    if(config == null) return;

 	  var offsets = $$(config.readAttribute('offset_element')).first().cumulativeOffset();

    var x = event.pointerX() - offsets[0];
    var y = event.pointerY();

    var url = config.readAttribute('callback') + '?x='+x+"&y="+y+"&url="+document.URL;
    $$('head').first().insert({bottom: new Element('script', {'src': url, 'type': 'text/javascript'})});
    return true;
  }
}

document.observe('click', ProtoHeatMap.record_click);
