/*
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 options = o || {};
    var maxHeight = options.maxHeight || 100;
    var className = options.className || 'expand';
    var textHeight = e.offsetHeight;
    
    if (textHeight > maxHeight) {
      element.css({overflow: 'hidden'});
      element.height(maxHeight);

      var moreLink = $("<p class='right truncate_link'>...More</p>").click(expand).addClass('more');
		var lessLink = $("<p class='right truncate_link'>...Less</p>").click(truncate).addClass('less');
      element.after(moreLink);
      element.after(lessLink);
   		lessLink.hide();

    }
    
	  function expand() {
	    element.animate({height: textHeight}, 'fast');
	    moreLink.hide();
		lessLink.show();
	  };
	  function truncate() {
	    element.animate({height: maxHeight}, 'fast');
      	lessLink.hide();
		moreLink.show();
	  };
	};
})(jQuery);
