Thanks for the example! I see that I shouldn't use CreateCommandButton() for this.
I have 1 more issue though: I've got the effect I wanted (if text is selected, the button is enabled, otherwise it's disabled).
This works fine until I switch over to the HTML view and back to Normal. The overridden onclick, onmouseover, onmouseout, etc still work, but the enable/ disable effect (hooked to editor.GetDocument() onselectionchange) is gone.
Note: Only the animation is gone, the code still works (I turn on and off the onclick, onmouseover functions in the onselectionchange function mentioned).
If it makes a difference, I'm inserting the button with InsertToolControl(), and it's not within the custombutton placeholder. It's actually an [insert hyperlink] button that inserts links to the document selected from a list of documents.
Any ideas? Thanks!