jQuery.fn.limitMaxlength = function(options){
  var settings = jQuery.extend({
    attribute: "maxlength",
    onLimit: function(){},
    onEdit: function(){},
    defaultMaxLength:199
  }, options);
  
  // Add the area for the information of the chars remaining
  jQuery(this).after('<span class=\'charsRemaining\'></span>');
  
  // Event handler to limit the textarea
  var onEdit = function(){
    var textarea = jQuery(this);
    var maxLength = parseInt(textarea.attr(settings.attribute));
    if(isNaN(maxLength) || maxLength < 1){
      maxLength = settings.defaultMaxLength;
    }

    if(textarea.val().length > maxLength){
      textarea.val(textarea.val().substr(0, maxLength));
      // Call the onlimit handler within the scope of the textarea
      textarea.siblings('.charsRemaining').css('color', 'red');
    }
    
    // Call the onEdit handler within the scope of the textarea
    var remaining = maxLength - textarea.val().length;
    textarea.siblings('.charsRemaining').text(textarea.val().length + " von " + maxLength + " Zeichen");
    if(remaining > 0){
      textarea.siblings('.charsRemaining').css('color', 'inherit');
    }
  }

  this.each(onEdit);

  return this.keyup(onEdit)
        .keydown(onEdit)
        .focus(onEdit);
}
/*
$(document).ready(function(){
  $('textarea').limitMaxlength();
});*/
