first pass at js - its bad but works.  todo: wrap into library