$(document).ready(function(){
    
    $('#responseBox .noticeBoxOK').ready(function(){
        
        if($('#responseBox .noticeBox').length == 0)
            return;
        
        $("body").append('<div id="popupWindow"><span id="close"></span><div id="wrap"><div id="popupContent"></div></div></div>') 
    
        $('#popupWindow').animate(
        {opacity: 1.0}, 
        {
            duration: 100, 
            specialEasing: {
               width:  'toggle',
               height: 'easeOutBounce'
            }, 
            complete: function() {
                
                $("#popupContent").replaceWith($('#responseBox .noticeBox'));
                
                $('#popupWindow #wrap').center(0, 0).css({"z-index" : "20"});
                
                $('#responseBox .noticeBoxOK').hide();
                
                var left =  ( $('#popupWindow #wrap').innerWidth() / 2 - 12 );
                
                var top  = - ( ($('#popupWindow #wrap').innerHeight() / 2) + 12 );

                $('#popupWindow #close').center(left, top).css({"z-index" : "20"});
                
                $("html").keydown(function(e){
                    if(e.keyCode==27)
                      exit();
                });

                $("#popupWindow").click(function(){ exit(); }); 

                $("#close").click(function(){ exit(); });
            } 
        })
        .css({
              "height":$("body").innerHeight(),
              "width": $("body").innerWidth()});
     
    });
    
    
    function exit(){
       
       $("#wrap").children().remove();
       
       $("#wrap").remove();
       
       $("#popupWindow").remove(); 
    }
    
    jQuery.fn.center = function (moveW, moveH) {
        this.css("position","absolute");
        this.css("top",  (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()  + moveH  + "px");
        this.css("left", (($(window).width()  - this.outerWidth())  / 2) + $(window).scrollLeft() + moveW  + "px");
        return this;
    }
    
});


