/**
 * Shows a dialog for the contact email on top of the page and
 * attaches the ajaxForm to the form within. On success, it will
 * change to a success callback.
 *
 * @param options.title The title for the dialog window
 * @param options.action The response action on form submission
 */
function majistiw_dialog_contact(options)
{
    $('#contact-email').click(function() {
        $('#dialog-email').dialog({
            autoOpen: false,
            width: '500px',
            title: options.title,
            modal: true,
            dialogClass: 'dialog'
        }).dialog('open');
    });

    $('#dialog-email').bind('dialogopen', function() {
       $form = $('#dialogEmailForm');
       $form.ajaxForm({
           action: options.action,
           successCallback: function(data) {
               $form.remove();
               $('<a />')
                    .attr('href', 'mailto:' + data)
                    .html(data)
                    .appendTo($('<div />')
                        .addClass('email')
                        .appendTo('#dialog-email'));
           }
       });
    });
}

/* on dom ready custom elements */
$(function() {
   /* bind fancybox on all rel links */
   $('a[rel=fancybox]').fancybox();
});

