
/**
 * Shows the info tooltip for a profile
 */
function showToolTip(event) {
	
	// get the info from the contents of the link
	var href = this.href;
	
	// from the href get the user id
	var memberIDs = [];
	href.scan(/\/([0-9]+)\//, function(match){ memberIDs.push(match[0]); });
	var memberID = memberIDs[0].gsub('\/', ''); // remove the / from either side of the ID
	
	// create the tooltip
	var f = $('m-info');
	f.update('');
	var div = new Element('div', { 'class' : 'toolTipContent' });
	var img = new Element('img', { 'src': '/images/spinner.gif' });
	div.insert(img);
	f.insert(div);
	
	// style it and position it
	var offset = Element.cumulativeOffset(this);
	var offsetLeft = offset.left + Element.getWidth(this) + 10;
	f.setStyle({ left: offsetLeft+'px', top: offset.top+'px' });
	
	// tell the tooltip to disappear when we hover off this link
	Event.observe(this, 'mouseout', function(event) { $('m-info').update(''); $('m-info').hide(); });
	
	// get the contents via ajax
	getToolTipContents(memberID);
	
	// finally, show it
	f.show();
	
	// prevent the onclick from going to the href
	event.stop();
	
}

/**
 * Retrieves the user info via AJAX
 */
function getToolTipContents(memberID) {
	
	new Ajax.Updater('m-info', '/ajax/tooltip/'+memberID);
	
}

/**
 * Adds a mouseover handler to each profile link.
 */
function addToolTips() {
		
	var links = $$('a.hasToolTip');
		
	for (var i = 0; i < links.length; i++) {
		links[i].observe('mouseover', showToolTip);
	}
	
}


/**
 * Set these items to run when the page loads
 */
document.observe('dom:loaded', addToolTips);
