// $Id$
(function($) {
    var BUTTON_PADDING = 28;
    var IMG_DIV_FMT =  '<div class="light" id="image-viewer">' +
        '<img src="_SRC_" width="_WIDTH_" height="_HEIGHT_" ' +
        'title="Click anywhere to close"/>' +
        '</div>';
    function _close(what) {
        $(what).dialog('close');
        $('.ui-dialog').remove();
    }
    $(document).ready(function() {
        $('.popup-image a').click(function() {
            var a=$(this).attr('href').split('?');
            var size=a[1].split('x');

            var s = IMG_DIV_FMT;
            $.each({
                _SRC_: a[0],
                _WIDTH_: size[0],
                _HEIGHT_: size[1]
            }, function(k,v) {
                var re = new RegExp(k);
                s=s.replace(re, v);
            });
            $(s).dialog({
                autoOpen: true,
                resizable: false,
                position: 'center',
                width: size[0],
                height: size[1],
                modal: true,
                overlay: {
                    opacity: 0.7,
                    'background-color': 'white',
                    cursor: 'pointer'
                },
                open: function() {
                    $(this).click(function() {
                        _close(this);
                    });
                    $('.ui-dialog-overlay').click(function() {
                        _close('#image-viewer');
                    });
                }});
            return false;
        });
        $('#flash_notice,#flash_error').dialog({
            resizable: false,
            position: ['center',100],
            width: 500,
            height: 76,
            modal: false,
            open: function(){
                $(this).show().animate({opacity: .8}, 4000)
                .fadeOut(1500, function() { $(this).remove() });
            }
        })
    });
})(jQuery);
