// (c) function easeOutQuart - adopted from AS version by Robert Penner (http://robertpenner.com/)
function easeOutQuart (t, b, c, d)
	{
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
	}

RollForm = function(toggler, element, range, endCallback)
    {
    this.toggler   = document.getElementById(toggler);
    this.element   = document.getElementById(element);
    this.range     = range;
    this.ease      = easeOutQuart;
	this.index     = 0;
	this.id		   = toggler;
	if (toggler=='q1' || toggler=='q2' || toggler=='q3' || toggler=='q4' ){
		// пусть появятся мгновенно
		this.time      = 0;//600;
		this.steps     = 1;//20;
		this.increment = 100;//1;		
	}
	else{
		// пусть плавно выплывают
		this.time      = 600;
		this.steps     = 20;
		this.increment = 1;				
	}
	this.delta     = this.time / this.steps;
	this.target    = null;
    this.showing   = false;
    this.callback  = endCallback;

    RollForm.instances.push(this);
    }

RollForm.prototype.toggle = function(hideOverride)
    {
	if(this.showing)
		{
		if(this.increment || hideOverride)
			{
			this.increment = -1;
			this.target = 0;
			}
		else if(!hideOverride)
			{
			this.increment = 1;
			this.target = this.steps;
			}
		}
	else
		{
		if(this.index == 0)
			{
			this.increment = 1;
			this.target = this.steps;

            for(var i = 0, ic = RollForm.instances.length; i < ic; ++ i)
                {
                var inst = RollForm.instances[i];

                if(inst == this)
                    continue;
                    
                    
			        // insert    
					if (!(this.id=='q1' || this.id=='q2' || this.id=='q3' || this.id=='q4')){
		                if(inst.target)
	    	                inst.toggle();}
                }
			}
		else
			{
			this.increment = -1;
			this.target = 0;
			}

		this.showing = true;
        var THIS = this;
		window.setTimeout(function(){THIS.tick()}, this.delta);
		}

	return false;
    }

RollForm.prototype.tick = function()
	{
	this.element.style.marginTop = this.ease(this.index = this.index + this.increment, -this.range, this.range, this.steps);

	if(this.index != this.target)
        {
        var THIS = this;
		window.setTimeout(function(){THIS.tick()}, this.delta);
        }
	else
        {
		this.showing = false;

        html = this.toggler.innerHTML.replace(/<\/?strong>/gi, "");
        if(this.target)
            this.toggler.innerHTML = "<strong>" + html + "</strong>";
        else
            this.toggler.innerHTML = html;

        if(this.callback)
            this.callback(!this.target);
        }
	}

RollForm.instances = new Array();