$(document).ready(addRefTitles);

function addRefTitles()
{
	var refs = $('.reference');
	var reflist = $('li');
	var i;
	
	for(i =0; i < refs.length; i++)
	{
		var match = findMatches(refs, reflist);
		if(match != null)
		{
                        var newTitle = $('#' + match.id + ' > span.reference-text').text()
			refs.title = newTitle;
			refs.children.title = newTitle;
		}
	}
}

function findMatches(ref, reflist)
{
	var i;
	var refId = ref.id.slice(9);
	if(refId.search("_") != -1)
	{
		refId  = refId.slice(0, refId.lastIndexOf('_')) + '-' + refId.slice(refId.lastIndexOf("_")+1, refId.lastIndexOf("-"));
	}
	for(i=0; i < reflist.length; i++)
	{
		var reflistId = reflist.id.slice(10);
		
		if(refId == reflistId) 
		{
			return reflist;
		}
	}
	return null;
}