cleanup javascript and integrate better with flipbox