Could I get a code review for my query dialog/lightbox code please?

Could I get a code review for my query dialog/lightbox code please?

Fairly new with jQuery, and am looking for a critique of my code. I am not entirely happy with a few things I have done.

1. Using an id to uniquely identify the buttons, and appending the "_dialog" string to it, so I can target the blocks of code i want to make visible. Seems a bit brittle, but I can't think of a better way.

2. The duplication when binding the hide functions.

3. General feeling that the code is not very modular/clean.

I just want to know how I can improve my jQuery coding.

Thanks

HTML
 
  1. <a href="#" class="dialog" id="login">login</a>
Javascript
 
  1. function Dialog() {

  2.     // Event handler for a dialog click.
  3.     $('a.dialog').click(function () {

  4.         var dialog = $("#" + this.id + "_dialog");

  5.         // Bind the hide functions here, as the elements have now been loaded into the DOM.
  6.         $("#overlay, #close").click(function () {
  7.             HideDialog(dialog)
  8.         });
  9.         window.onresize = function () {
  10.             CentreBoxInViewport(dialog);
  11.         };

  12.         SetupDialog(dialog);
  13.         return false;
  14.     });

  15.     // Event handler for an image click.
  16.     $('div.status > a').click(function () {

  17.         // Get the object for the lightbox.
  18.         var dialog = $("#lightbox");

  19.         // Get the path to the image.
  20.         var path = this.getAttribute("href");

  21.         // Bind the hide functions here, as the elements have now been loaded into the DOM.
  22.         $("#overlay, #close").click(function () {
  23.             HideDialog(dialog)
  24.         });
  25.         window.onresize = function () {
  26.             CentreBoxInViewport(dialog);
  27.         };

  28.         SetupLightBox(path, dialog);
  29.         return false;
  30.     });
  31. }

  32. function SetupLightBox(path, dialog) {

  33.     // Create a new image.
  34.     var image = new Image();

  35.     // The onload function must come before we set the image's src, see link for explanation.
  36.     // http://www.thefutureoftheweb.com/blog/image-onload-isnt-being-called.

  37.     // Anonymous function set to onload event, to make sure we only proceed if the image has been loaded.
  38.     image.onload = function () {
  39.         $('#image').attr('src', path)
  40.         CentreBoxInViewport(dialog);
  41.         ShowOverlay(dialog);
  42.     };

  43.     // Set the src, and show the image.
  44.     image.src = path;
  45. }

  46. function SetupDialog(dialog) {
  47.     CentreBoxInViewport(dialog);
  48.     ShowOverlay(dialog);
  49. }

  50. function ShowDialog(dialog) {
  51.     dialog.fadeTo(200, 1);
  52. }

  53. function HideDialog(dialog) {
  54.     dialog.fadeTo(200, 0, function () {
  55.         dialog.hide();
  56.         HideOverlay();
  57.     });
  58. }

  59. function ShowOverlay(dialog) {
  60.     $('#overlay').fadeTo(200, 0.5, function () {
  61.         ShowDialog(dialog)
  62.     });
  63. }

  64. function HideOverlay() {
  65.     $('#overlay').fadeTo(200, 0, function () {
  66.         $('#overlay').hide();
  67.     });
  68. }

  69. function CentreBoxInViewport(dialog) {

  70.     // Get the dimensions of the viewport.
  71.     var height = $(window).height()
  72.     var width = $(window).width();

  73.     // Calculate the position of the lightbox.
  74.     var boxtop = (height / 2) - dialog.height() / 2;
  75.     var boxleft = (width / 2) - dialog.width() / 2;

  76.     // Position the box.
  77.     dialog.css({
  78.         top: boxtop,
  79.         left: boxleft
  80.     });
  81. }