refactor javascript code to remove erb from javascript functions. add callback functions to reduce number of global variables needed.