function init(evt) {
    if (ip === null) return;
    // give initial timestamp
    recordHistory([Date(), 'load ' + encodeURIComponent(document.URL)]);
    // attach click_thru to each <a>
    $$('a').invoke('observe', 'click', clickThruListener);
}

/* record click-thru info: time, link, current page */
function clickThruListener(evt) {
    recordHistory([Date(), encodeURIComponent(this.href)]);
}

function recordHistory(str) {
    new Ajax.Request("index.cgi", 
		     { 'parameters': { 
			 'time': str[0], 
			 'other': str.slice(1),
			 'Context': 'Homepage/clickThru'
		     }});
}

Event.observe(window, 'load', init);
Event.observe(window, 'unload', function(evt) { 
    if (ip === null) return;
    recordHistory([Date(), 'unload '+encodeURIComponent(document.URL)]);
});
