/*
truncates elements that pass a certain height.
adds a "view more" link to display the rest of the content.

a different approach than standard truncation which relies on character counting.
character counting may not be desireable when elements have short words, but a 
number of line breaks.

usage:
  //using defaults
  $('css_expression').summary();
  
  //overriding options
  $('css_expression').summary({maxHeight: 200, className: 'view-more'});
*/
(function($) {
  $.fn.summary = function(options) {
	  return this.each(function() {
	    new $.Summary(this, options);
		});
	};

	$.Summary = function(e, o) {
	  var element = $(e);
	  var text = element.find('p');
	  var options = o || {};
    var maxHeight = element.height();
    var textHeight = text.height();
    
    if (textHeight > maxHeight) {
    	var StrippedString = text.html().replace(/(<([^>]+)>)/ig,"");
	    var aText = StrippedString.split(' ');
	    
	    while (text.height() > maxHeight) {
	    	aText.pop();
	    	text.html(aText.join(' '));
	    }
	
	    aText.pop();
			text.html(aText.join(' ')+' ...');
    }
	};
})(jQuery);
