(function ($) {

// attach to jQuery
    $.extend({
        plDialog: function (options)
        {
            var modalType = {
                alert: 'alert',
                dialog: 'dialog'
            };

            var defaults = {
                confirmMessage: '',
                dialogHeader: '',
                confirmText: '',
                cancelText: '',
                height: 200,
                width: 'auto',
                position: ['center', 'center'],
                modalType: modalType.dialog,
                confirmCmd: function () {
                    confirmCmd();
                },
                cancelCmd: function () {
                    cancelCmd();
                },
                cssFineAdjustment: function () {
                    cssFineAdjustment();
                },
                addButton: ''
            };

            options = $.extend({}, defaults, options);

            function confirmCmd() {
                $('#dialog-confirm.modal-body').dialog("close");
            }

            function cancelCmd() {
                $('#dialog-confirm.modal-body').dialog("close");
            }

            function cssFineAdjustment() {
                $('.ui-dialog-titlebar').addClass('modal-header');
                $('.ui-dialog-titlebar-close').remove();
                $('.modal-header').removeClass('ui-dialog-titlebar');
                $('.modal-header').removeClass('ui-widget-header');
                $('.modal-header').removeClass('ui-corner-all');
                $('.modal-header').removeClass('ui-helper-clearfix');
                $('.ui-dialog-buttonset').addClass('modal-footer');
                $('.modal-footer').removeClass('ui-dialog-buttonset');
                $('.ui-dialog-content').addClass('modal-body');
                $('.modal-body').removeClass('ui-dialog-content');
                $('.modal-body').removeClass('ui-widget-content');
                $('#ui-dialog-title-dialog-confirm').replaceWith('<h4 class="ui-dialog-title" id="ui-dialog-title-dialog-confirm"><b>' + options.dialogHeader + '</b></h4>');
            }

            function getButtons() {
                var button = {
                    "confirm": {
                        text: options.confirmText,
                        id: 'dialog-confirm_confirm',
                        class: 'modalSaveBtn btn btn-primary',
                        click: function () {
                            options.confirmCmd();
                        }
                    }
                };

                var cancelBtn = {
                    "cancel": {
                        text: options.cancelText,
                        id: 'dialog-confirm_cancel',
                        class: 'btn',
                        click: function () {
                            options.cancelCmd();
                        }
                    }
                };

                if (options.modalType === modalType.dialog) {
                    button = $.extend({}, button, options.addButton, cancelBtn);
                }
                return button;
            }

            this.showConfirmDialog = function () {
                var backdrop = $("<div />")
                        .addClass("dialog-backdrop")
                        .addClass("modal-backdrop")
                        .addClass("fade")
                        .addClass("out")
                        .css("z-index", "125");
                $("#content").append(backdrop);
                setTimeout(function () {
                    $('.dialog-backdrop').removeClass("out").addClass('in');
                }, 10);
                $("<div />").attr("id", "dialog-confirm")
                        .html(options.confirmMessage)
                        .dialog({
                            draggable: false,
                            resizable: false,
                            modal: true,
                            height: options.height,
                            width: options.width,
                            position: options.position,
                            dialogClass: 'modal',
                            title: '<h4 class="ui-dialog-title" id="ui-dialog-title-dialog-confirm"><b>' + options.dialogHeader + '</b></h4>',
                            buttons: getButtons(),
                            close: function () {
                                $('.dialog-backdrop').remove();
                            }
                        });
                options.cssFineAdjustment();
            };

            $(document).keyup(function (e) {
                if (e.keyCode === 27) {
                    $('#dialog-confirm_cancel').click();
                }
            });
        }
    });
})(jQuery);