Cleanup duplicate vars, unused params, and hoisting.

var i was being declared in the same function multiple times.
$attr and event in resize callback were not being used.
Moving variable declarations to top of function, to be a bit more explicit because of hoisting.