$(document).ready(function() {
  $('li#contact a')
    .nyroModal({
                closeButton: $('<a>', 'X').addClass('nyroModalClose').attr({ id: 'closebut', title: 'close' })
                .append($('<img>').attr({src: 'images/fancy_closebox.png'}).addClass('round_close')),
                endFillContent : function (n, settings) {
                                   $('form', n.content).submit(function(e){
                                    e.preventDefault();
                                    var args = (new Array()).concat([ { name: 'send', value: 1 }],
                                                                    $(this).serializeArray());
                                    $.ajax({
                                      url    : './contact.cgi',
                                      type   : 'POST',
                                      data   : args,
                                      error  : function (XMLHttpRequest, textStatus, errorThrown){
                                                 console.log(textStatus + ': ' + errorThrown);
                                      },
                                      success: function (data, textStatus) {
                                        var reply = $('<div>').addClass('welcome').append(data);
                                        $('div.welcome', n.content).replaceWith(reply).nyroModal();
                                      },
                                      dataType: 'html',
                                    });
                                    return false;
                                   } )
                                 },
               })
  }
)
