/**
 * @author paolo
 */

 function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}
 function init(){
	setMaxLength();
}

var penitenze=new Array(
	"Subscribe at least to three new social networks before the sun will rise tomorrow and you will be forgiven",
	"Upload at least 10 photos of you as a child on Flickr and you will be forgiven",
	"Change your personal description on Facebook and let the world now you are a sinner, and you will be forgiven",
	"Write I am a sinner on your weblog and you will be forgiven",
	"Convince your grandmather to subscribe to Facebook and you will be forgiven",
	"Make at least 50 new friends on Facebook before the morning, and you will be forgiven",
	"Send an email to 2 of your enemies and ask for peace, and you will be forgiven",
	"Tag every photo that you have online with the world Sinner and you will be forgiven",
	"Cancel your best friend from your Facebook friend list, and you will be forgiven",
	"Unsubscribe at least a social network before the sun goes down tomorrow, and you will be forgiven"
);

 function mostraPenitenza(){
	new Effect.Opacity('assoluzione', {duration:2, from:0, to:1.0});
	var caso =  Math.round( Math.random(1)*penitenze.length)-1;
	if (caso < 0 ){caso = 0};
	$('penitenza').innerHTML = penitenze[caso];
	setTimeout("nascondi()",25000);
}

function nascondi(){
	$('assoluzione').style.display ="none";
}