Actually first time button is clicked, we assign a value of 1000 to FadeTimeLeft:
element.FadeTimeLeft = TimeToFade;
Then in the animateFade() function, the first time it is called, we subtract 33 from a 1000 to get 967:
element.FadeTimeLeft -= elapsedTicks;
Now next time the button is clicked, if coinciding a transition, then we subtract FadeTimeLeft from TimeToFade:
element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
This doesn't make sense to me. We are now subtracting 967 (current value of FadeTimeLeft, if this is second click and occuring during the transition) from 1000 to get 33 and then assigning it to FadeTimeLeft. But if FadeTimeLeft is now 33, then the animatino will be over. Its value should be 967 at this point so we can continue decrementing it by 33.
I'm obviously missing something here. Thanks for response.