jQuery.fn.shortenize = function(maxlen) {
	return this.each(function(){
		if (typeof(maxlen) == 'undefined') { maxlen = 30; } // javascript sucks and can't
															// handle default argument values
		var outstring = "";
		var words = this.innerHTML.split(" ");

		for (i=0; i<words.length; i++) {
			word = words[i];
			
			if (word.length > maxlen) {
				outword = word.substring(0, maxlen / 2 - 3)
						+ ' ... '
						+ word.substring(word.length - (maxlen / 2 + 3), word.length)
			} else {
				outword = word;
			}
			
			if (word.indexOf('://') != -1) {
				outword = '<a href="'+word+'" title="'+word+'">'+outword+'</a>';
			}

			outstring += outword + ' ';
		}

		this.innerHTML = outstring;
		
	});
};

jQuery.fn.fitwithin = function(widthinpixels) {
	return this.each(function(){
		if (typeof(widthinpixels) == 'undefined')
			{ widthinpixels = 200; } 	// javascript sucks and can't
										// handle default argument values
		
		fontsize = parseInt(jQuery(this).css('font-size'));
		fontwidth = fontsize * 0.4;
		numofcharstoshow = widthinpixels / fontwidth;

		fulltext = this.innerHTML;
		shorttext = fulltext.substr(0, numofcharstoshow);

		if (numofcharstoshow < fulltext.length) {
			this.innerHTML = '<span class="shortened_comment" title="'
						   + fulltext + '">' + shorttext + ' ... </span>';
		}
	});
};
