jQuery.fn.wordcount = function(options) {
    
    var options = jQuery.extend({
        'counter': null,
        'update': function(element, words) {
            jQuery(this.counter).text(words.length);
        }
    }, options);
    
    return this.each(function(i, item) {
        
        function getWords(element) {
            var sVal = jQuery(element).val();
            aTmp = sVal.split(' ');
            aWords = [];
            for (var i=0; i < aTmp.length; i++) {
                sTmp = jQuery.trim(aTmp[i]);
                if (sTmp.length > 0) aWords.push(sTmp);
            };
            return aWords;
        }
        
        jQuery(item).keyup(function() {
            // Count and apply update
            options.update.apply(options, [jQuery(this), getWords(this)]);
        });
        
        // Initial apply
        
        options.update.apply(options, [jQuery(item), getWords(item)]);
        
    });
    
}
