using extra var i to keep track of state of div

If `i` only has two possible values, might as well use a boolean.