/**
 * Blit Character Counter plugin 1.0
 *
 * Copyright (c) 2008 Blit, Inc (http://blit.com/)
 * MIT license (blit.com/licenses/mit.html)
 */
jQuery.fn.char_counter = function(max_len) {
   this.keyup(function(e) {
     if (!this.$char_counter) {
       this.$char_counter = $(this).siblings('.char_counter');
       if (this.$char_counter.length==0) this.$char_counter = $(this).parent().append('<div class="char_counter"></div>').find('.char_counter:last');
     }
     var curr_len = $(this).val().length;
     if (curr_len<max_len) {
       this.$char_counter.html((max_len-curr_len) + ' characters left')
       return true;
     }
     this.$char_counter.html('CHARACTER LIMIT REACHED');
     return false;
   });
   this.keydown(function(e) {
     var curr_len = $(this).val().length;
     if (curr_len>=max_len) {
       if (e.keyCode==8 || e.keyCode==36) return true;
       return false;
     }
     return true;
   });
   return this;
}
