/* ------------------------------------------------------------------------
	jquery.charlimit
	
	Developped By: Jerry Tian -> twitter.com/travid
	Version: 1.0
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */
(function($){
	  
	$.fn.limitChars = function(vars) {
		var element = this;
		var limit = (vars.limit != undefined) ? vars.limit : 140; 
		var infodiv = (vars.infodiv != undefined) ? vars.infodiv : "#infodiv"; 
		var text = element.val();
		var textlength = text.length;
		$(infodiv).text('(' + limit + " characters left)");
		if(textlength > limit)
		{
			$(infodiv).html('(cannot accept more than '+limit+' characters)');
			element.val(text.substr(0,limit));
			return false;
		}
		else
		{
			remain = limit - textlength;
			$(infodiv).html('(' + remain + ' characters left)');
			return true;
		}
	};
})(jQuery);  
