How to write my own Widget?

How to write my own Widget?

Hi I want to know how to write my own widget so I can create customized jQuery UI component.

For example on Safari Online, they have made an excellent feature where the table of content for a book appears aside the main content. When the user clicks < button, the TOC window shrinks. I particular liked that and would like to know how to do something like that in JQuery UI.

I tried to read how to develop a widget tutorial and tried reading source code but it contains so many strange things that I haven't seen before. I have been working with JavaScript and jQuery for some time. I want to know how others get started in jQuery UI development?