    jQuery.fn.twitterCounter = function(options) {
   var curSize = $(this).val().length;
   var charsLeft = options['limit'] - curSize;
   var types = ['ok', 'watch', 'warning', 'error'];
   var x = {};
   
   $.each(types, function(){
      var el = this.toString();
      x[el] = {'Max' : options[el + 'Size'], 
      'Style' : options[el + 'Style'].substring(0, 1) == '.' || options[el + 'Style'].substring(0, 1) == '#' ? options[el + 'Style'].substring(1, options[el + 'Style'].length) : options[el 
+ 'Style'], 
      'Type' : options[el + 'Style'].substring(0, 1) == '.' ? 'class' : 'id'}
   });

   for( var i=0; i < types.length; i++)
   {
      var el = types[i].toString();

      // Last Element check
      if( i+1 < types.length ) {
         var nextEl = types[i+1].toString();
         // console.debug(charsLeft, el, x[el]['Max'], x[nextEl]['Max']+1, charsLeft > x[nextEl]['Max'] && charsLeft < x[el]['Max'] + 1);
         if( charsLeft > x[nextEl]['Max'] && charsLeft < x[el]['Max'] + 1) {
            clean();
         }
      } else {
         // console.debug(charsLeft, el, x[el]['Max'], x[nextEl]['Max']+1, charsLeft < x[el]['Max'] + 1);
         if( charsLeft < x[el]['Max']  ) {
            clean();
         }
      }
   }
   
   $(options['counter']).text(charsLeft);
   
   if(charsLeft < 0)
   {
        options['error_callback']();
   }
   else
   {
        options['ok_callback']();
   }
   
   // Add an event so the counter updates when the user types.
   $(this).one('keyup', function(){
      $(this).twitterCounter(options);
   });
   
   
   function clean() {
      if( x[el]['Type'] == 'class' ) {
         $.each(types, function(){
            var temp = this.toString();
            if( $(options['counter']).hasClass(temp) ) {
               $(options['counter']).removeClass(temp);
            }
         });
         $(options['counter']).addClass(x[el]['Style']);
      } else {
         $(options['counter']).id(x[el]['Style']);
      }
   }
};


