﻿(function(b) {
    var j = { dragStart: "start.draggable", drag: "drag.draggable", dragStop: "stop.draggable", maxHeight: "maxHeight.resizable", minHeight: "minHeight.resizable", maxWidth: "maxWidth.resizable", minWidth: "minWidth.resizable", resizeStart: "start.resizable", resize: "drag.resizable", resizeStop: "stop.resizable" }; b.widget("ui.dialog", { _init: function() {
        this.originalTitle = this.element.attr("title"); var c = this, a = this.options, d = a.title || this.originalTitle || "&nbsp;", e = b.ui.dialog.getTitleId(this.element), f = (this.uiDialog =
 b("<div/>")).appendTo(document.body).hide().addClass("ui-dialog ui-widget ui-widget-content ui-corner-all " + a.dialogClass).css({ position: "absolute", overflow: "hidden", zIndex: a.zIndex }).attr("tabIndex", -1).css("outline", 0).keydown(function(g) { a.closeOnEscape && g.keyCode && g.keyCode == b.ui.keyCode.ESCAPE && c.close(g) }).attr({ role: "dialog", "aria-labelledby": e }).mousedown(function(g) { c.moveToTop(false, g) }); this.element.show().removeAttr("title").addClass("ui-dialog-content ui-widget-content").appendTo(f);
        var h = (this.uiDialogTitlebar = b("<div></div>")).addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix").prependTo(f), i = b('<a href="#"/>').addClass("ui-dialog-titlebar-close ui-corner-all").attr("role", "button").hover(function() { i.addClass("ui-state-hover") }, function() { i.removeClass("ui-state-hover") }).focus(function() { i.addClass("ui-state-focus") }).blur(function() { i.removeClass("ui-state-focus") }).mousedown(function(g) { g.stopPropagation() }).click(function(g) { c.close(g); return false }).appendTo(h);
        (this.uiDialogTitlebarCloseText = b("<span/>")).addClass("ui-icon ui-icon-closethick").text(a.closeText).appendTo(i); b("<span/>").addClass("ui-dialog-title").attr("id", e).html(d).prependTo(h); h.find("*").add(h).disableSelection(); a.draggable && b.fn.draggable && this._makeDraggable(); a.resizable && b.fn.resizable && this._makeResizable(); this._createButtons(a.buttons); this._isOpen = false; a.bgiframe && b.fn.bgiframe && f.bgiframe(); a.autoOpen && this.open()
    }, destroy: function() {
        this.overlay && this.overlay.destroy();
        this.uiDialog.hide(); this.element.unbind(".dialog").removeData("dialog").removeClass("ui-dialog-content ui-widget-content").hide().appendTo("body"); this.uiDialog.remove(); this.originalTitle && this.element.attr("title", this.originalTitle)
    }, close: function(c) {
        var a = this; if (false !== a._trigger("beforeclose", c)) {
            a.overlay && a.overlay.destroy(); a.uiDialog.unbind("keypress.ui-dialog"); a.options.hide ? a.uiDialog.hide(a.options.hide, function() { a._trigger("close", c) }) : a.uiDialog.hide() && a._trigger("close", c); b.ui.dialog.overlay.resize();
            a._isOpen = false; if (a.options.modal) { var d = 0; b(".ui-dialog").each(function() { if (this != a.uiDialog[0]) d = Math.max(d, b(this).css("z-index")) }); b.ui.dialog.maxZ = d } 
        } 
    }, isOpen: function() { return this._isOpen }, moveToTop: function(c, a) {
        if (this.options.modal && !c || !this.options.stack && !this.options.modal) return this._trigger("focus", a); if (this.options.zIndex > b.ui.dialog.maxZ) b.ui.dialog.maxZ = this.options.zIndex; this.overlay && this.overlay.$el.css("z-index", b.ui.dialog.overlay.maxZ = ++b.ui.dialog.maxZ); c = { scrollTop: this.element.attr("scrollTop"),
            scrollLeft: this.element.attr("scrollLeft")
        }; this.uiDialog.css("z-index", ++b.ui.dialog.maxZ); this.element.attr(c); this._trigger("focus", a)
    }, open: function() {
        if (!this._isOpen) {
            var c = this.options, a = this.uiDialog; this.overlay = c.modal ? new b.ui.dialog.overlay(this) : null; a.next().length && a.appendTo("body"); this._size(); this._position(c.position); a.show(c.show); this.moveToTop(true); c.modal && a.bind("keypress.ui-dialog", function(d) {
                if (d.keyCode == b.ui.keyCode.TAB) {
                    var e = b(":tabbable", this), f = e.filter(":first")[0],
 h = e.filter(":last")[0]; if (d.target == h && !d.shiftKey) setTimeout(function() { f.focus() }, 1); else d.target == f && d.shiftKey && setTimeout(function() { h.focus() }, 1)
                } 
            }); b([]).add(a.find(".ui-dialog-content :tabbable:first")).add(a.find(".ui-dialog-buttonpane :tabbable:first")).add(a).filter(":first").focus(); this._trigger("open"); this._isOpen = true
        } 
    }, _createButtons: function(c) {
        var a = this, d = false, e = b("<div></div>").addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"); this.uiDialog.find(".ui-dialog-buttonpane").remove();
        typeof c == "object" && c !== null && b.each(c, function() { return !(d = true) }); if (d) { b.each(c, function(f, h) { b('<button type="button"></button>').addClass("ui-state-default ui-corner-all").text(f).click(function() { h.apply(a.element[0], arguments) }).hover(function() { b(this).addClass("ui-state-hover") }, function() { b(this).removeClass("ui-state-hover") }).focus(function() { b(this).addClass("ui-state-focus") }).blur(function() { b(this).removeClass("ui-state-focus") }).appendTo(e) }); e.appendTo(this.uiDialog) } 
    }, _makeDraggable: function() {
        var c =
 this, a = this.options, d; this.uiDialog.draggable({ cancel: ".ui-dialog-content", handle: ".ui-dialog-titlebar", containment: "document", start: function() { d = a.height; b(this).height(b(this).height()).addClass("ui-dialog-dragging"); a.dragStart && a.dragStart.apply(c.element[0], arguments) }, drag: function() { a.drag && a.drag.apply(c.element[0], arguments) }, stop: function() { b(this).removeClass("ui-dialog-dragging").height(d); a.dragStop && a.dragStop.apply(c.element[0], arguments); b.ui.dialog.overlay.resize() } })
    }, _makeResizable: function(c) {
        c =
 c === undefined ? this.options.resizable : c; var a = this, d = this.options; this.uiDialog.resizable({ cancel: ".ui-dialog-content", alsoResize: this.element, maxWidth: d.maxWidth, maxHeight: d.maxHeight, minWidth: d.minWidth, minHeight: d.minHeight, start: function() { b(this).addClass("ui-dialog-resizing"); d.resizeStart && d.resizeStart.apply(a.element[0], arguments) }, resize: function() { d.resize && d.resize.apply(a.element[0], arguments) }, handles: typeof c == "string" ? c : "n,e,s,w,se,sw,ne,nw", stop: function() {
     b(this).removeClass("ui-dialog-resizing");
     d.height = b(this).height(); d.width = b(this).width(); d.resizeStop && d.resizeStop.apply(a.element[0], arguments); b.ui.dialog.overlay.resize()
 } 
 }).find(".ui-resizable-se").addClass("ui-icon ui-icon-grip-diagonal-se")
    }, _position: function(c) {
        var a = b(window), d = b(document), e = d.scrollTop(); d = d.scrollLeft(); var f = e; if (b.inArray(c, ["center", "top", "right", "bottom", "left"]) >= 0) c = [c == "right" || c == "left" ? c : "center", c == "top" || c == "bottom" ? c : "middle"]; if (c.constructor != Array) c = ["center", "middle"]; if (c[0].constructor == Number) d +=
 c[0]; else switch (c[0]) { case "left": d += 0; break; case "right": d += a.width() - this.uiDialog.outerWidth(); break; default: case "center": d += (a.width() - this.uiDialog.outerWidth()) / 2 } if (c[1].constructor == Number) e += c[1]; else switch (c[1]) { case "top": e += 0; break; case "bottom": e += a.height() - this.uiDialog.outerHeight(); break; default: case "middle": e += (a.height() - this.uiDialog.outerHeight()) / 2 } e = Math.max(e, f); this.uiDialog.css({ top: e, left: d })
    }, _setData: function(c, a) {
        j[c] && this.uiDialog.data(j[c], a); switch (c) {
            case "buttons": this._createButtons(a);
                break; case "closeText": this.uiDialogTitlebarCloseText.text(a); break; case "dialogClass": this.uiDialog.removeClass(this.options.dialogClass).addClass("ui-dialog ui-widget ui-widget-content ui-corner-all " + a); break; case "draggable": a ? this._makeDraggable() : this.uiDialog.draggable("destroy"); break; case "height": this.uiDialog.height(a); break; case "position": this._position(a); break; case "resizable": var d = this.uiDialog, e = this.uiDialog.is(":data(resizable)"); e && !a && d.resizable("destroy"); e && typeof a == "string" &&
 d.resizable("option", "handles", a); e || this._makeResizable(a); break; case "title": b(".ui-dialog-title", this.uiDialogTitlebar).html(a || "&nbsp;"); break; case "width": this.uiDialog.width(a); break
        } b.widget.prototype._setData.apply(this, arguments)
    }, _size: function() { var c = this.options; this.element.css({ height: 0, minHeight: 0, width: "auto" }); var a = this.uiDialog.css({ height: "auto", width: c.width }).height(); this.element.css({ minHeight: Math.max(c.minHeight - a, 0), height: c.height == "auto" ? "auto" : Math.max(c.height - a, 0) }) } 
    });
    b.extend(b.ui.dialog, { version: "1.7.2", defaults: { autoOpen: true, bgiframe: false, buttons: {}, closeOnEscape: true, closeText: "close", dialogClass: "", draggable: true, hide: null, height: "auto", maxHeight: false, maxWidth: false, minHeight: 150, minWidth: 150, modal: false, position: "center", resizable: true, show: null, stack: true, title: "", width: 300, zIndex: 1E3 }, getter: "isOpen", uuid: 0, maxZ: 0, getTitleId: function(c) { return "ui-dialog-title-" + (c.attr("id") || ++this.uuid) }, overlay: function(c) { this.$el = b.ui.dialog.overlay.create(c) } });
    b.extend(b.ui.dialog.overlay, { instances: [], maxZ: 0, events: b.map("focus,mousedown,mouseup,keydown,keypress,click".split(","), function(c) { return c + ".dialog-overlay" }).join(" "), create: function(c) {
        if (this.instances.length === 0) {
            setTimeout(function() { b.ui.dialog.overlay.instances.length && b(document).bind(b.ui.dialog.overlay.events, function(d) { return (b(d.target).parents(".ui-dialog").css("zIndex") || 0) > b.ui.dialog.overlay.maxZ }) }, 1); b(document).bind("keydown.dialog-overlay", function(d) {
                c.options.closeOnEscape &&
 d.keyCode && d.keyCode == b.ui.keyCode.ESCAPE && c.close(d)
            }); b(window).bind("resize.dialog-overlay", b.ui.dialog.overlay.resize)
        } var a = b("<div></div>").appendTo(document.body).addClass("ui-widget-overlay").css({ width: this.width(), height: this.height() }); c.options.bgiframe && b.fn.bgiframe && a.bgiframe(); this.instances.push(a); return a
    }, destroy: function(c) {
        this.instances.splice(b.inArray(this.instances, c), 1); this.instances.length === 0 && b([document, window]).unbind(".dialog-overlay"); c.remove(); var a = 0; b.each(this.instances,
 function() { a = Math.max(a, this.css("z-index")) }); this.maxZ = a
    }, height: function() { if (b.browser.msie && b.browser.version < 7) { var c = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), a = Math.max(document.documentElement.offsetHeight, document.body.offsetHeight); return c < a ? b(window).height() + "px" : c + "px" } else return b(document).height() + "px" }, width: function() {
        if (b.browser.msie && b.browser.version < 7) {
            var c = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), a = Math.max(document.documentElement.offsetWidth,
 document.body.offsetWidth); return c < a ? b(window).width() + "px" : c + "px"
        } else return b(document).width() + "px"
    }, resize: function() { var c = b([]); b.each(b.ui.dialog.overlay.instances, function() { c = c.add(this) }); c.css({ width: 0, height: 0 }).css({ width: b.ui.dialog.overlay.width(), height: b.ui.dialog.overlay.height() }) } 
    }); b.extend(b.ui.dialog.overlay.prototype, { destroy: function() { b.ui.dialog.overlay.destroy(this.$el) } })
})(jQuery);  
