/* COMPANY FLOW */
var move_px = 2; // move the boxes 2 px to the left
var move_ms = 40; // every 40 millisecond

var boxes; // all boxes
var box_area; // div around the boxes
var box_distance; // distance between 2 boxes

var interval_id = 0; // interval id for scrolling


function flow_init()
{
	// init box objects
	box_area = document.getElementById("flow-area");
	boxes = new Array();
	for(i = 0; i < companies_count; i++)
	{
		boxes[boxes.length] = document.getElementById("flow-box-" + i);
	}
	
	if(!boxes.length)
		boxes = box_area.childNodes;
	
	box_distance = parseInt(boxes[1].style.left) - parseInt(boxes[0].style.left)
	
	// set interval to move the boxes
	interval_id = setInterval("move_boxes(-1)", move_ms);
}
function flow_stop()
{
	// stop interval if still exists
	if(interval_id > 0)
		clearInterval(interval_id);
	interval_id = 0;
}

// move all boxes (direction -1 => left, 1 => right)
function move_boxes(direction)
{
	// get new position of first box
	box0_x = (parseInt(boxes[0].style.left) + (move_px * direction))
	// how many boxes are missing on the left side
	boxes_missing_left = Math.round((box0_x / box_distance) + 0.5);
	
	// move first box
	boxes[0].style.left = box0_x + "px";
	
	// arrange all boxes
	for(i = 1; i < boxes.length; i++)
	{
		// arrange on the right
		if(i < (boxes.length - boxes_missing_left))
		{
			boxes[i].style.left = (box0_x + (i * box_distance)) + "px";
		}
		// arrange on the left
		else
		{
			boxes[i].style.left = (box0_x - ((boxes.length - i) * box_distance)) + "px";
		}
	}
	
	// first box left area on the left and boxes are flowing to the left
	if((boxes_missing_left < 0) && (direction == -1))
	{
		// move first box to the right
		boxes[0].style.left = ((parseInt(boxes[boxes.length - 1].style.left)) + box_distance) + "px";
	}
	
	// first box left area on the right and boxes are flowing to the right
	else if((boxes_missing_left >= boxes.length) && (direction == 1))
	{
		// move first box to the left
		boxes[0].style.left = ((parseInt(boxes[boxes.length - 1].style.left)) - ((boxes.length - 1) * box_distance)) + "px";
	}
}

// default move
function start_move(direction)
{
	flow_stop();
	move_px = 2;
	interval_id = setInterval("move_boxes(" + direction + ")", move_ms);
}
// manually moving to the left (-1) or right (1)
function start_fast_move(direction)
{
	flow_stop();
	move_px = 4;
	interval_id = setInterval("move_boxes(" + direction + ")", move_ms / 2);
}
// stop moving
function stop_move()
{
	clearInterval(interval_id);
}