﻿jQuery.fn.sysmodal || (function($) {
    jQuery.fn.sysmodal = function(opt) {
        return this.each(function() {
            if ($('#sysmodal').length == 0) {
                $('body').append('<div id="sysmodal" />');
            }

            //armazena a largura e a altura da tela
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Define largura e altura do div#mask iguais ás dimensçoes da tela
            $('#sysmodal').css({ top: 0, width: 0, 'width': maskWidth, 'height': maskHeight });

            //efeito de transição
            $('#sysmodal').fadeIn(1000);
            $('#sysmodal').fadeTo("slow", 0.5);


            //armazena a largura e a altura da janela
            var winH = $(window).height();
            var winW = $(window).width();
            //centraliza na tela a janela popup
            if (opt.top) {
                $(this).css('top', opt.top);
            }
            else {
                $(this).css('top', winH / 2 - $(this).height() / 2);
            }

            if (opt.left) {
                $(this).css('left', opt.left);
            }
            else {
                $(this).css('left', winW / 2 - $(this).width() / 2);
            }
            //efeito de transição
            $(this).fadeIn(2000);

            var nome = this.id;
            $('#' + this.id + ' .close, #sysmodal').click(function(e) {
                e.preventDefault();
                $('#sysmodal, #' + nome).hide();
            });
        });

    };
})(jQuery);
