Just wanted to share how to create a custom close button with jQuery UI's Dialog Widget
Create a dialog this way
// TODO store modalDialog somewhere so you can call modalDialog.dialog('open'); and modalDialog.dialog('close'); when required
The key is, when using the .dialog function, jQuery UI wraps the dialog in its own div (the $(this).parent().find(".ui-dialog-titlebar") line).
Hope this helps someone.