function initEllipses () {
	var ellipsisSeq = 0;
	var ellipsisEls = document.getElementsByTagName('span');
	for (var i = 0; i < ellipsisEls.length; i++) {
		var el = ellipsisEls[i];
		if (el.className.match(/ellipsis/)) {
			var maxLength = el.getAttribute("maxLength");
			if (!maxLength) maxLength = 10;
			
			var longText = el.innerHTML;
			var shortText = trim(stripTags(el.innerHTML));
			if (shortText.length <= maxLength) continue;
			var lastChar = shortText.substring(maxLength-1, maxLength);
			if ( lastChar == ' ' ){
			    // if the last character happens to be a white space, don't worry about it 		    
			    shortText = shortText.substring(0, maxLength);
			}
			else {
			    // find the next white space
			    var nextSpaceIndex = shortText.indexOf(' ', maxLength);
			    if ( nextSpaceIndex == -1 ) { // next space not found
			        continue; // return the whole comment 
			    }
			    else {
			       shortText = shortText.substring(0, nextSpaceIndex + 1);
			    }
			    
			}
            // to avoid words getting cut in the middle, we need to do some tricks here
			el.id = "ellipsis" + ellipsisSeq++;
			el.innerHTML = 
			'<span id="' + el.id + 'short">' + shortText +
			' <a href="javascript:ellipsisLong(\'' + el.id + '\')">(more...)</a>' +
			'</span>' +
			'<span style="display:none" id="' + el.id + 'long">' + longText +
			' <a href="javascript:ellipsisShort(\'' + el.id + '\')">(less...)</a> ' +
			'</span>';
		}
	}
}

function stripTags (t) {
	while (t.match(/<.*>/)) t = t.replace(/<[^>]*>/, "");
	return t;
}

function trim (t) {
	return t.replace(/^[ \r\n\t]*/, "").replace(/[ \r\n\t]*$/, "");
}

function ellipsisShort (id) {
	document.getElementById(id + "short").style.display = "inline";
	document.getElementById(id + "long").style.display = "none";
}

function ellipsisLong (id) {
	document.getElementById(id + "short").style.display = "none";
	document.getElementById(id + "long").style.display = "inline";
}

