/* 
	LinearFlow: Arranges items in a clickable line
	Copyright (C) 2008 Best Foot Forward

	You must include baseflow.js before including this file.
*/

LinearFlow = Class.create (BaseFlow,
{
	initialize : function ($super, elem, opts)
	{
		$super (elem, opts);

		var linearopts = {
			'padding' : 20
		}
		Object.extend (linearopts, opts);
		this.padding = linearopts.padding;
	},

	position : function ($super, anim)
	{
		/* Reset the x counter to 0 before positioning */
		this.x_counter = 0;
		this.target_x = 0;

		for (var i = 0; i < anim.target; ++i)
			this.target_x += this.stack [i].width + this.padding;

		/* Place the target in the center of elem */
		this.target_x += (this.stack [anim.target].width / 2) - (this.width / 2);
		$super(anim);

		/* Linearflow limits animation ticks to 100 */
		if (anim.ticks > 25)
			return false;

		return true;
	},

	positionItem : function (anim, index, pos)
	{
		/* Calculate "target" position of item */
		var target_x = this.x_counter - this.target_x;
		pos.x = pos.left + (target_x - pos.left) / 5;
		pos.y = 50;
		pos.z = 0;

		this.x_counter += this.stack [index].width + this.padding;
	}
});

