(function($) {
    
    $.fn.dialogBox = function(options){

        $(this).click(function(){
            dialogShow(this);
            return false; 
        }); 
        
        function dialogShow(object){
            var dialogOpen = $(object).attr("id");
            $('body').append('<div id="box_dialog-overlay" class="box_dialog-overlay" style="display:none;" />');      
            $('body').css({height:'100%'});                                                                
            $('#box_dialog-overlay').fadeIn(600, function(){      
                $('body').append('<div id="box_dialog" class="box_dialog" style="display:none;" />');
                $('#box_dialog').fadeIn(600, function(){
                        $.ajax({
                            url: 'ipp2011/html/statement-'+dialogOpen+'.html',
                            dataType: 'html',
                            contentType: 'application/x-www-form-urlencoded; charset=iso-8859-1;', 
                            beforeSend:function(){
                	           $('#box_dialog').html('<div class="ajax-loading"><img src="ipp2011/images/ajax-loader.gif" alt="Loading..." /></div>');
                            },
                            success:function(data){
                               $('#box_dialog').empty().html(data).mCustomScrollbar("vertical", 400, "easeOutCirc", 1.05, "auto", "yes", "yes", 10);
                                    $('#box_dialog_close').click(function(){
                                        dialogClose(this);
                                        return false;            
                                    }); 
                            },
                            error:function(){
                                $('#box_dialog').html('<p class="ajax-error"><strong>Oops!</strong> Try that again in a few moments.</p>');
                            }
                        });	       
                 });               
            });             
            $('#box_dialog-overlay, #box_dialog_close').click(function(){
                dialogClose(this);
                return false;            
            });    
        };    
        
        function dialogClose(object){
            $('#box_dialog').fadeOut(600, function(){
                $(this).remove();
                $('#box_dialog-overlay').fadeOut(600, function(){
                     $(this).remove();                                 
                });                                 
            });                    
        };

    };        
})(jQuery);
