
function AdjustTitle(id)
{
	var w = document.getElementById(id);
	var title = w.innerHTML;
	w.title = title.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');;
	w.parentNode.parentNode.parentNode.getElementsByTagName('img')[0].title = w.title;
	var p = w.parentNode.parentNode;
	var hmax = parseInt(p.offsetHeight);
	p.style.height = 'auto';
	var h1 = parseInt(p.offsetHeight);
	if (h1 > hmax)
	{
		w.innerHTML = '&nbsp;';
		var h0 = parseInt(p.offsetHeight);
		if (h0 < hmax) h0 = hmax;
		////// adjust title to make it fit. Binary search
		var i_min = 0, i_max = title.length;
		while (i_min < i_max)
		{
			var i = Math.ceil((i_min + i_max)/2);
			w.innerHTML = title.substr(0, i) + '...';
			if (parseInt(p.offsetHeight)>h0) i_max = i-1;
			else i_min = i;
		}
		w.innerHTML = title.substr(0, i_min) + '...';
		if (parseInt(p.offsetHeight) >= h1) w.innerHTML = title;
	}
	p.style.height = hmax + 'px';
}


