feedback_ctl = function(settings){
	this.settings = {
		trans_duration:1000,
		message_delay:500,
		message_ok:'<p>Сообщение отправлено</p>',
		message_fail:'<p>Не удалось отправить сообщение!</p>',
		message_wait:'<p>Идёт отправка...</p>'
	};
	
	for(var i in settings) this.settings[i] = settings[i];

	this.showform =function(){
		this.anim_show.delay(this.settings.message_delay);
	};
	
	this.hideform =function(){
		this.anim_hide();
	};
	
	this.anim_show = function(){
		this.fields_fade.start(1);
		this.fields_slide.slideIn();
		this.result_fade.start(0);
		this.result_slide.slideOut();	
	};

	this.anim_hide = function(){
		this.fields_fade.start(0);
		this.fields_slide.slideOut();
		this.result_fade.start(1);
		this.result_slide.slideIn();
	};
	
	this.init = function(){
		alert(this.settings.message_delay);
		this.request = new Request.HTML({method:'post', url:'.',
			onSuccess:function(){
				$('feedback-form').reset();
				$('fb-result').setStyles({'background-image':'url(/images/ok.png)'}).innerHTML = this.settings.message_ok;
				this.showform();
			}.bind(this),
			onFailure:function(){
				$('fb-result').setStyles({'background-image':'url(/images/fail.png)'}).innerHTML = this.settings.message_fail;
				this.showform();
			}.bind(this),
			onRequest:function(){
				$('fb-result').setStyles({'background-image':'url(/images/wait.gif)'}).innerHTML = this.settings.message_wait;
				this.hideform();
			}.bind(this)
		});
		
		$('feedback-form').addEvent('submit', function(e){
			var e = new Event(e).preventDefault();
			this.request.send(e.target.toQueryString());
		}.bind(this));
		
		this.fields_slide = new Fx.Slide('fb-fields', {mode:'vertical', duration:this.settings.trans_duration});
		this.fields_fade = new Fx.Tween('fb-fields', {property:'opacity', duration:this.settings.trans_duration});
		this.result_slide = new Fx.Slide('fb-result', {mode:'vertical', duration:this.settings.trans_duration});
		this.result_fade = new Fx.Tween('fb-result', {property:'opacity', duration:this.settings.trans_duration});
		this.result_slide.hide();
		this.result_fade.set(0);
		$('fb-result').removeClass('hidden');
	}
	
	window.addEvent('domready', this.init.bind(this));
}

/* 
var fbctl = new feedback_ctl({
	massage_delay:<?=(int) str_replace(',', '.', $this->settings['message_shown'])?>*1000,
	message_ok:'<?=str_replace("'", "\'", $this->settings['message_sent'])?>'
});
*/
