I think the first side to attack takes the average speed of team 1 and compares with average speed of team 2 who gets higher goes first, just a guess. And then highest speed in that team moves first.
Its just who ever is fastest goes first, there team goes first then, the team order is of speed as well, and when enemies attach the go in order of speed then.