using extra var i to keep track of state of div