Event.attach(window, "load", function() {
		var fieldset = $i("questions");
		var legend = $t("legend", fieldset)[0];
		var div = $c("slider", "div", fieldset)[0];
		if (legend && div) {
			var slider = new Slider(div);
			Event.attach(legend, "click", function() {
					if (slider.current == 0 || slider.current == slider.frames) {
						var classes = Class.get(fieldset);
						slider[!!(classes && classes.contains("selected")) ? "hide" : "show"]();
					}
				}, this);
			Event.attach(slider, "showstart", function() { Class.add(fieldset, "selected"); }, this);
			Event.attach(slider, "hideend", function() { Class.del(fieldset, "selected"); }, this);
		}
	}, this);
Event.attach(window, "load", function() {
		var fieldset = $i("loginn");
		var legend = $t("legend", fieldset)[0];
		var div = $c("slider", "div", fieldset)[0];
		if (legend && div) {
			var slider = new Slider(div);
			Event.attach(legend, "click", function() {
					if (slider.current == 0 || slider.current == slider.frames) {
						var classes = Class.get(fieldset);
						slider[!!(classes && classes.contains("selected")) ? "hide" : "show"]();
					}
				}, this);
			Event.attach(slider, "showstart", function() { Class.add(fieldset, "selected"); }, this);
			Event.attach(slider, "hideend", function() { Class.del(fieldset, "selected"); }, this);
		}
	}, this);

function Slider(slider, duration) {
	this.slider = slider;
	this.duration = (duration || 1);
	this.delay = 1;
	this.fps = 200;
	this.frames = this.fps * this.duration;
	this.current = 0;
	this.start = 0;
	this.showEasing = Easing.easeOut;
	this.hideEasing = Easing.easeOut;
};

Slider.prototype = {
	show: function() {
		this.showing = true;
		this.current = 0;
		this.easing = this.showEasing;
		this._onshowstart();
		this.end = this.slider.scrollHeight;
		this.started = new Date();
		this.action();
	},
	
	hide: function () {
		this.showing = false;
		this.current = 0;
		this.easing = this.hideEasing;
		this._onhidestart();
		this.end = this.slider.scrollHeight;
		this.started = new Date();
		this.action();
	},
	
	_onshowstart: function() {},
	_onshowend: function() {},
	_onhidestart: function() {},
	_onhideend: function() {},
	
	action: function() {
		if (this.current < this.frames) {
			this.check();
			var value = this.easing(this.current, this.start, this.end, this.frames);
			if (!this.showing) {
				value = this.end - value - this.start;
			}
			this.resize(value);
			this.thread = setTimeout(Function.bind(this.action, this), this.delay);
		} else {
			this.thread = null;
			this["_on" + (this.showing ? "show" : "hide") + "end"]();
		}
	},
	
	check: function() {
		var time = (new Date() - this.started);
		var calcFrame = Math.round((time * this.frames) / (this.duration * 1000)) + 1;
		this.current = (calcFrame <= this.frames ? calcFrame : this.frames);
	},
	
	resize: function(height) {
		height = Math.floor(height);
		var old = this.slider.style.height.match(/^\d+/);
		this.slider.style.height = height + "px";
		window.scrollBy(0, height - old);
	}
};

var Easing = {
	linear: function(t, b, c, d) {
		return c*t/d + b;
	},
	easeIn: function(t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOut: function(t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOut: function(t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	}
};