$(function() {
    var config = {
        'press-dialog': {
            width: 450,
            height: 90
        },
        'join-us-dialog': {
            width: 790,
            buttons: {
                'Enviar': function() {
                    $(this).find("form").submit();
                },
                'Cancelar': function() {
                    $(this).dialog("close");
                }
            }
        },
        'commerce-dialog': {
            width: 400,
            height: 110
        }
    }
    
    var dialogs = $(".top-dialog").map(function() {return $(this).attr("class").split(/[ ]+/);})
    dialogs = dialogs.filter(function() {return this != "top-dialog" && /-dialog$/.test(this)});
    
    dialogs.each(function() {
        var dlg = this;
        var cfg = config[dlg];
        $("." + dlg).dialog({
            autoOpen: false,
            modal: true,
            resizable: false,
            width: cfg.width,
            height: cfg.height,
            buttons: cfg.buttons,
            open: function() {
                $(this).parents('.ui-dialog-buttonpane button:eq(0)').focus(); 
            }
        });
        
        $("#open-" + dlg).click(function() {
           $("." + dlg).dialog('open'); 
        });
    });
});
