Guestbook = new Class({

	initialize: function(numero_messaggi){
		
		this.a = null;
		this.last = 0;
		this.first = 17;
		this.current = 0;
		this.numero_messaggi = numero_messaggi;
		
		this.initAccordionHor();
	},
	
	setCurrent: function(c){
	
		$('tog_' + this.current).style.background='#eeb659';
		this.current = c;
		$('tog_' + this.current).style.background='#bd5000';
	},
	
	prevAccordion: function(){
	
		$('msg_' + (this.last)).style.display = 'none';
		$('msg_' + (this.first+1)).style.display = '';
		
		this.last++;
		this.first++;
		
		if(this.first == this.numero_messaggi-1) $('prev').style.display = 'none';
		if(this.last > 0) $('next').style.display = '';
		
		this.a.display(this.first);
		this.setCurrent(this.first);
	},
	
	nextAccordion: function(){
	
		$('msg_' + (this.last-1)).style.display = '';
		$('msg_' + (this.first)).style.display = 'none';
		
		this.last--;
		this.first--;
		
		if(this.first < this.numero_messaggi) $('prev').style.display = '';
		if(this.last == 0) $('next').style.display = 'none';
		
		this.a.display(this.last);
		this.setCurrent(this.last);
	},
	
	initAccordionHor: function(){
	
		var divs=document.getElementsByTagName('div');
		var i=divs.length-1;
		var togglers = new Array();
		var stretchers = new Array();
		do {
			if(divs[i].className=="TOG") togglers.push(divs[i]);
			if(divs[i].className=="STR") stretchers.push(divs[i]);
		}
		while(--i);
		
		this.a=new Accordion(togglers,stretchers,{
				start:false,
				show:false,
				height: false,
				width: true,
				display: 0,
				alwaysHide: false,
				duration: 200,
				fixedWidth: 230,
				fps: 50,
				opacity: false,
				onActive:function(toggler,i){
					toggler.addClass('active');
					i.addClass('active');
				},
				onBackground:function(toggler,i){
					toggler.removeClass('active');
					i.removeClass('active');
				}
			}
		);
		
		$('accordion').style.display = '';
	},
	
	checkFields: function(){
	
		var val = new Validator();
		var ck = true;
		
		ck = val.validateFieldAndSetError('autore', true) != true ? false : ck;
		ck = val.validateFieldAndSetError('email', true, val.options.regex.EMAIL) != true ? false : ck;
		ck = val.validateFieldAndSetError('titolo', true) != true ? false : ck;
		ck = val.validateFieldAndSetError('testo', true) != true ? false : ck;
		ck = val.validateFieldAndSetError('cinput', true) != true ? false : ck;
		
		if(ck == true) return true;
		else return false;
	}
});
