﻿/*
Precis
- a fast, simple truncation function
- largely based on jquery.truncate: http://www.reindel.com/truncate/
*/
jQuery.fn.precis = function(max, settings) {
	settings = jQuery.extend({
		breaks: false,
		trail: '...'
	}, settings);

	return this.each(function() {
		var $this = jQuery(this);
		var orig = jQuery.trim($this.html().replace(/\r\n/gim, ''));
		var reBreak = /<br[^<>]*\/?>/gim;
		var reTags = /<\/?[^<>]*\/?>/gim;
		var aLines = (settings.breaks) ? orig.split(reBreak) : new Array(orig);

		for (x in aLines) {
			var clean = aLines[x].replace(reTags, '');
			if (clean.length > max) {
				clean = jQuery.trim(clean.substring(0, max));
				aLines[x] = [clean, settings.trail].join('');
			}
		}

		$this.html(aLines.join('<br />'));
	});
};