javascript out of sync, what is going on