Javascript pathfinder