dialog close event

dialog close event


I can't seem to find where this has been answered before...if it has,
please point me in the right direction.
I am using the jquery dialog. When a user clicks the X in the title
bar I want to receive an event.
The reason for this is that if a user clicks on the link that opened
the dialog, multiple dialogs get opened. I can look for the click on
the link and compensate, but if the user clicks on the titlebar "X" to
close the window, I never know it and therefore the user cannot open
the window again using the link.
Currently I do this:
var popIsOpen =
false;
function emailPopup()
{
if(dialogIsOpen == false)
{
$
("#popup").hide();
$
("#popup").load("email.html");
$
("#popup").dialog();
$
("#popup").show("slow");
popIsOpen =
true;
}
}
A form is loaded into the dialog and submitting or canceling will
switch "popIsOpen" back to false.
I tried the following for the X click:
$(document).ready(function()
{
$(".ui-dialog-titlebar-close").click(function()
{

alert("closing");
popIsOpen =
false;
});
});
But that didn't work. I am not a javascript programmer and I am just
guessing at all this since the docs don't seem to address this issue
(or maybe I missed it).
I am using the latest stable release of both jquery and jquery-ui in
firefox 2.
Thanks
Brian