jQuery/javascript running functions synchronously