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

RollForms = function(element, range, endCallback, parameter)
    {
    this.element   = document.getElementById(element);
    this.range     = range;
    this.ease      = easeOutQuarts;
	this.index     = 0;
	this.time      = 600;
	this.steps     = 20;
	this.delta     = this.time / this.steps;
	this.increment = 1;
	this.target    = null;
    this.showing   = false;
    this.callback  = endCallback;
	this.parameter = parameter ? parameter : "top";
    }

RollForms.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;
			}
		else
			{
			this.increment = -1;
			this.target = 0;
			}

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

	return false;
    }

RollForms.prototype.tick = function()
	{
	this.element.style[this.parameter] = 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;
        if(this.callback)
            this.callback(!this.target);
        }
	}