var share_link_anchor;
function share_link(link, url, title) {
	var container = $('#share_form');
	
	if (share_link_anchor == link && container.css('display') == 'block') {
		container.hide();
		return false;
	}
	share_link_anchor = link;

	$("#share_fb").attr('href', share_url("http://www.facebook.com/sharer.php?u={u}&t={t}", url, title));
	$("#share_digg").attr('href', share_url("http://digg.com/submit?phase=2&url={u}&title={t}", url, title));
	$("#share_mixx").attr('href', share_url("http://mini.mixx.com/submit/story?page_url={u}&title={t}", url, title))
	$("#share_ybuzz").attr('href', share_url("http://buzz.yahoo.com/submit?submitUrl={u}&submitHeadline=&t={t}", url, title));
	$("#share_gbmarks").attr('href', share_url("http://www.google.com/bookmarks/mark?op=edit&bkmk={u}&title={t}", url, title));
	
	container.css({ top: '-9999px' }).show();
	
	var pos = Drupal.absolutePosition(link);
	pos.x -= Math.floor(container.width() / 2 - link.offsetWidth / 2);
	
	if (pos.x + container.get(0).offsetWidth > document.body.offsetWidth) {
		pos.x = document.body.offsetWidth - container.get(0).offsetWidth;
	}
	else if (pos.x < 0) {
		pos.x = 0;
	}
	container.css({ left: pos.x + 'px', top: pos.y + link.offsetHeight + 3 + 'px' });	
	return false;
}

function share_url(base, url, title) {
	base = base.replace('{u}', url);
	return base.replace('{t}', title);
}

