(function($){
  $.fn.truncate = function(options) {
    var options = $.extend({}, $.fn.truncate.defaults, options);
 
    return this.each(function(){
 
      obj = $(this);
      body = obj.html();
 
      if( body.length > options.minChars ) {
        firstPartText = body.substring(0, options.chars);
        secondPartText = body.substring(options.chars, body.length);

				
				firstPart = $('<span />').addClass('first_part')
				                         .html(firstPartText);
				
				ending = $('<span />').addClass('ending')
				                      .html(options.ending);
				
				moreLink = $('<a />').attr('href', '#').addClass('more_link')
				                     .html(options.moreText);
				secondPart = $('<span />').addClass('second_part')
				                          .html(secondPartText).hide();
				
				lessLink = $('<a />').attr('href', '#').addClass('less_link')
				                     .html(options.lessText).hide();
				
				obj.html(firstPart).append(ending).append(secondPart)
				   .append(moreLink).append(lessLink);
				
				moreLink.click(function(){
					// hide more link
					$(this).hide();
					
					// get the text container
					textContainer = $(this).parent();
					
					// hide ending
					textContainer.children('.ending').hide();
					
					// show the second part
					textContainer.children('.second_part').css('display','inline');
				
					// show less link
					textContainer.children('.less_link').css('display', 'inline');
					
					return false;
				});
				
				lessLink.click(function(){
					// hide less link
					$(this).hide();
					
					// get the text container
					textContainer = $(this).parent();
					
					// show ending
					textContainer.children('.ending').css('display', 'inline');
					
					// hide the second part
					textContainer.children('.second_part').hide();
					
					// show more link
					textContainer.children('.more_link').css('display', 'inline');
					
					return false;
				});
      }
    });
  }
 
  $.fn.truncate.defaults = {
    minChars: 50,
    chars: 42,
    ending: '...',
		moreText: '[lire la suite]',
		lessText: '[fermer]'
  };
})(jQuery);