Problem with swap()

Problem with swap()


I've encountered this intermittent, thoroughly unreliable (in terms of
being able to reproduce it) problem with swap().
Basically I have an image that has borders on it.
That image gets animated to change its width and/or height (plus
possibly a couple of others like top and left, but immaterial here).
What was happening very occasionally in Firefox, and even rarer, in
IE, was that borders were getting set to zero, and I couldn't work out
why or when. I completely re-factored my code, and got rid of the
problem (I thought) by removing all possible calls to myimage.width()
and myimage.height(), and where I couldn't remove them entirely I
spaced them out, so that a width() call did not follow immediately
after a height() call.
That seemed to solve the problem, but then I tested Safari (2 and 3)
and the problem came back again - in spades!
By putting alerts all the way through my code and jQuery, I finally
narrowed it down (I think!) to swap().
It would appear that the reinstatement of the 'old' values is
sometimes not happening. The width/height get reported back correctly,
it's just that the borders don't get reinstated.
I put the following modification into my jQuery ...
swap: function(e,o,f) {
    var now = {}; // added
    for ( var i in o ) {
        now[i] = e.style[i]; // added
//        e.style["old"+i] = e.style[i]; // commented out
        e.style[i] = o[i];
    }
    e.swaps = now; // added
    f.apply( e, [] );
    for ( i in o ) // just removed the var (i already declared)
        e.style[i] = now[i]; // added
//        e.style[i] = e.style["old"+i]; // commented out
},
... and I now don't have a problem! (Or at least I haven't managed to
get it fail yet!)
The way I reasoned it was that maybe the extra properties on style
were causing problems. I couldn't see that the old values really
needed to be stored on the element itself, particularly not in style,
but I could see that the called function *may* want to know what the
'proper' values should be. So I store the 'proper' values locally - in
'now' - and set a swaps property on the element itself before calling
the callback; then use 'now' to reinstate the 'proper' values at the
end.
Sorry it's such a long explanation but have some sympathy for how long
it's taken me to track this down!
Anyway, does anyone have any thoughts, opinions, input, previous
experience of the same problem ... anything?
[Just reading back over it, it might be safer to reinstate from the
element's swaps property, just in case the called function changes the
values it wants put back - can't see why it would, but still... .
Trouble is, this way works and it might not if I change it!]