function movement(action, tag, startvalue, endvalue, stepsize, delay, integer)
{
	this.action = action;
	this.tag = tag;
	this.startvalue = startvalue;
	this.endvalue = endvalue;
	this.stepsize = stepsize;
	this.delay = delay;
	this.integer = integer;
	this.curvalue = this.startvalue;
}

movement.prototype.setTag = function(value)
{
	this.tag = value;
}

movement.prototype.start = function()
{
	this.totaltime = this.delay * (this.endvalue - this.startvalue) / this.stepsize;
	this.starttime = (new Date()).getTime();
	this.getId();
	this.step();
}

movement.prototype.stop = function()
{
	this.releaseId();
}

movement.prototype.getId = function()
{
	var i = 0;
	for(; i < movement.items.length; i++)
	{
		if(!movement.items[i])
		{
			break;
		}
	}
	this.id = i;
	movement.items[i] = this;
	return i;
}

movement.prototype.releaseId = function()
{
	movement.items[this.id] = null;
	this.id = null;
}

movement.items = new Array();

movement.step = function(id)
{
	movement.items[id].step();
}

movement.prototype.step = function()
{
	var done = false;
	var nowvalue;
	if(this.totaltime == 0)
	{
		done = true;
	}
	else
	{
		var now = (new Date()).getTime();
		var nowpart = (now - this.starttime) / this.totaltime;
		nowvalue = this.startvalue + nowpart * (this.endvalue - this.startvalue);
		if(this.integer)
		{
			nowvalue = Math.round(nowvalue);
		}
		if(this.endvalue > this.startvalue)
		{
			if(nowvalue >= this.endvalue)
			{
				done = true;
			}
		}
		else
		{
			if(nowvalue <= this.endvalue)
			{
				done = true;
			}
		}
	}
	if(done)
	{
		nowvalue = this.endvalue;
	}
// alert("part = " + nowpart + " value = " + nowvalue);
	this.action(this.tag, nowvalue);
	if(!done)
	{
		window.setTimeout("movement.step(" + this.id + ")", this.delay);
	}
	else
	{
		this.stop();
		if(this.next)
		{
			this.next.start();
		}
	}
}

function wait(time)
{
	this.delay = time;
}

wait.prototype = new movement(function f(t, v) {}, null, 0, 1, 1, 1, true);

function animation()
{
	this.streams = new Array();

}

animation.prototype.addStream = function(stream)
{
	var id = this.streams.length;
	this.streams[id] = stream;
	return id;
}

animation.prototype.addToStream = function(id, item)
{
	var p = this.streams[id];
	var q = null;
	while(p)
	{
		q = p;
		p = p.next;
	}
	if(q)
	{
		q.next = item;
	}
	else
	{
		this.streams[id] = item;
	}
	item.next = null;
}

animation.prototype.setTag = function(value)
{
	for(var i = 0; i < this.streams.length; i++)
	{
		var p = this.streams[i];
		while(p)
		{
			p.setTag(value);
			p = p.next;
		}
	}
}

animation.prototype.start = function()
{
	for(var i = 0; i < this.streams.length; i++)
	{
		this.streams[i].start();
	}
}

