

            var dialogs = new Array();

            function bind_popup_maps(selector) {
                if (typeof(selector) == 'undefined') selector = '.popup_map';
                $(selector).click(function(event){
                    href = $(this).attr('href');
                    title = $(this).attr('title');

                    loader = $('<div />').addClass('loader_big');

                    dialog = $('<div />').addClass('popup').addClass('loader_big').attr('title', title).appendTo('body').dialog({
                        autoOpen: true,
                        minWidth: 200,
                        minHeight: 300,
                        resizable: false,
                        modal: true,
                        draggable: false
                    }).append(loader).load(
                        href, {content_only: 1}, function() {
                            map_width = $(this).find('img.map').outerWidth();
                            google_map_width = $(this).find('div').outerWidth();
                            $(this).dialog('option', 'width', Math.max(map_width, google_map_width)+25);
                            $(this).dialog('option', 'position', 'center');
                            $(this).removeClass('loader_big');
                        }
                    ).bind( "dialogclose", function(event, ui) {
                        $(this).remove();
                    });

                    event.preventDefault();
                });
            }


            $(document).ready(function(){

                bind_popup_maps();

                $('.events_calendar li a, .community_calendar a.event').click(function(event) {
                    var href = $(this).attr('href');

                    var re = /id=([0-9]*)/i;
                    var result = re.exec(href);

                    if (typeof(result[1]) == 'undefined') return;
                    var id = result[1];

                    var dialog;

                    if (typeof(dialogs[id]) != 'undefined') {
                        dialog = dialogs[id];
                        dialog.dialog('open');
                    }
                    else {
                        var title = $(this).html();

                        dialog = $('<div class="popup"><div class="loader_big"><\/div><\/div>').attr('title', title).appendTo('.page');

                        $(dialog).dialog({
                            autoOpen: true,
                            width: 600,
                            resizable: false,
                            modal: true,
                            buttons: {
                                "Close": function() {
                                    $(this).dialog("close");
                                }
                            }
                        });


                        $.get(href, {content_only: 1}, function(data){
                            dialog.html(data);
                        });

                        dialogs[id] = dialog;
                    }

                    event.preventDefault();

                    dialog.parents('.ui-dialog').find('button').each(function(){
                        $(this).children('span').html($(this).attr('text'));
                    });
                });


                $('.ui-widget-overlay').live("click", function() {
                    $(".popup").dialog("close");
                });
            });

