J.J. Barea leaving Mavericks, heading to Timberwolves