function init(){
	if($$('textarea').length !=0 ) setMaxLength()
}

function start_slideshow(start_frame, end_frame, delay) {
	setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}

function switch_slides(frame, start_frame, end_frame, delay) {
	return (function() {
  	Effect.Fade('slideshow' + frame);
		if (frame == end_frame) {
			frame = start_frame;
		} else {
			frame = frame + 1;
		}
		setTimeout("Effect.Appear('slideshow" + frame + "');", 850);
		setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
 	})
 }

function home_init() {
	start_slideshow(1, 5, 8000);
}

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';
		this.value = this.value.substring(0, maxLength);	
	}else{
		this.relatedElement.className = '';
	}
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

document.observe('dom:loaded', init)
Event.observe(window, 'load', home_init, false);
