jQuery(document).ready(function() {

	/* SCRIPT SETTINGS */
	var maxChars = 140;
	var rate = 200;
	var entryFieldId = 'SweepstakesEntryDescription';
	var counterFieldId = 'character-count';

	/* DON'T TOUCH */
	var _description = jQuery('#'+entryFieldId);
	var _counter = jQuery('#'+counterFieldId);
	
	var _currentCount = _description.val().length;
	_counter.html(maxChars-_currentCount);
	
	_description.keypress(function(event) {
		_currentCount = _description.val().length;	
		if (_currentCount == maxChars && event.keyCode != 8) { event.preventDefault(); }
	});	
	_description.keyup(function(event) {
		_currentCount = _description.val().length;
		if (_currentCount > maxChars) {
			_description.val(_description.val().substr(0,maxChars));
			_counter.html(0);
		}
		else { _counter.html(maxChars-_currentCount); }
	});	
	_timer = setInterval(function(){
		_currentCount = _description.val().length;
		if (_currentCount > maxChars) {
			_description.val(_description.val().substr(0,maxChars));
			_counter.html(0);
		}
	}, rate);	
});
