// Apply character counter to TextCounterWidgets. Uses the
// simplyCountable JQuery extension.

function activateCounters() {	
	// Backwards compatible
	$('textarea.TextCounterWidget').each(function() {
		$(this)
			.wrap(
				$("<div>").addClass("TextCounterWidget")
			)
			.removeClass("TextCounterWidget");		
	});

	$('div.TextCounterWidget').not(".noajax").not(".ajaxed").each(function() {		
		$(this).addClass('ajaxed');

		var counter = $(this).children(".counter");

		if(counter.length == 0) {
			counter = $('<div>').addClass('counter');
			$(this).append(counter);
		}
	
		$(this).children("textarea").simplyCountable({
			'counter' : counter
		});
	});
}

ajaxifyFunctions.push(activateCounters);

$(activateCounters);

