/*
 *
 * Textarea Word Count Jquery Plugin
 * Version 1.0
 *
 * Copyright (c) 2008 Roshan Bhattarai
 * website : http://roshanbh.com.np
 * http://roshanbh.com.np/2008/10/jquery-plugin-word-counter-textarea.html
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 *
*/

jQuery.fn.wordCount = function(params){
	var p = {
		counterElement:"display_count"
	};
	var total_words;

	if(params) {
		jQuery.extend(p, params);
	}

	//for each keypress function on text areas
        jQuery(this).bind('keyup click blur focus change paste', function()
	{
		total_words=this.value.split(/[\s\.\?]+/).length;
		if (total_words < 150)
                {
                    jQuery('#'+p.counterElement).html(total_words);
                }
                else
                {
                    jQuery('#'+p.counterElement).html('<span style="color: red;">' + total_words + '!</span>');
                }
	});
};