javascript 2 dimensional tree implementation