Javascript: shorten text
function shortenText(textLength,elem){
elem.each(function() {
var that = $(this),
title = that.text(),
chars = title.length;
if (chars > textLength - 3) {
var newTitle = title.substring(0, textLength) + "...";
that.text(newTitle);
}
});
}