(function(a){var e={maximize:!1,minimize:!1,dblclick:!1,titlebar:!1,icons:{maximize:"ui-icon-extlink",minimize:"ui-icon-minus",restore:"ui-icon-newwin"},events:{load:null,beforeCollapse:null,beforeMaximize:null,beforeMinimize:null,beforeRestore:null,collapse:null,maximize:null,minimize:null,restore:null}},c,f={init:function(b){a(this).dialog||a.error("jQuery.dialogExtend Error : Only jQuery UI Dialog element is accepted");b=b||{};b.icons=b.icons||{};b.events=b.events||{};c=a.extend({},e,b);c.icons=
a.extend({},e.icons,b.icons);c.events=a.extend({},e.events,b.events);a(this).each(function(){a(this).data("dialog-state","normal").dialogExtend("_verifySettings").dialogExtend("_initEvents").dialogExtend("_initStyles").dialogExtend("_initButtons").dialogExtend("_initTitleBar").dialogExtend("_trigger","load")});return this},collapse:function(){var b=a(this).dialog("widget").find(".ui-dialog-titlebar").height()+15;a(this).dialogExtend("_trigger","beforeCollapse").dialogExtend("_saveSnapshot").data("dialog-state",
"collapsed").dialog("option",{height:b,maxHeight:b}).hide().dialog("widget").find(".ui-dialog-buttonpane:visible").hide().end().find(".ui-dialog-titlebar").css("white-space","nowrap").end().find(".ui-dialog-content").dialogExtend("_trigger","collapse");return this},maximize:function(){var b=a(window).height()-11,c=a(window).width()-11;a(this).dialogExtend("_trigger","beforeMaximize").dialogExtend("_saveSnapshot").data("dialog-state","maximized").dialogExtend("_toggleButtons").dialog("widget").css("position",
"fixed").find(".ui-dialog-content").show().dialog("widget").find(".ui-dialog-buttonpane").show().end().find(".ui-dialog-content").dialog("option",{resizable:!1,draggable:!1,height:b,width:c,position:[1,1]}).dialog("widget").draggable("option","handle",null).find(".ui-dialog-draggable-handle").css("cursor","text").end().find(".ui-dialog-content").dialogExtend("_trigger","maximize");return this},minimize:function(){a(this).dialogExtend("_trigger","beforeMinimize").dialogExtend("_saveSnapshot").data("dialog-state",
"minimized").dialogExtend("_toggleButtons").dialog("widget").hide().find(".ui-dialog-content").dialogExtend("_trigger","minimize");return this},restore:function(){var b=a(this).data("dialog-state");a(this).dialogExtend("_trigger","beforeRestore").data("dialog-state","normal").dialogExtend("_toggleButtons").dialogExtend("maximized"==b?"_restoreFromMaximized":"minimized"==b?"_restoreFromMinimized":"collapsed"==b?"_restoreFromCollapsed":a.error("jQuery.dialogExtend Error : Cannot restore dialog from unknown state '"+
b+"'")).dialog("widget").show().dialogExtend("_trigger","restore");return this},_initButtons:function(){var b=this,d=a(b).dialog("widget").find(".ui-dialog-titlebar");a(d).append('<a class="ui-dialog-titlebar-maximize ui-corner-all" href="#"><span class="ui-icon '+c.icons.maximize+'">maximize</span></a>').append('<a class="ui-dialog-titlebar-minimize ui-corner-all" href="#"><span class="ui-icon '+c.icons.minimize+'">minimize</span></a>').append('<a class="ui-dialog-titlebar-restore ui-corner-all" href="#"><span class="ui-icon '+
c.icons.restore+'">restore</span></a>').find(".ui-dialog-titlebar-maximize,.ui-dialog-titlebar-minimize,.ui-dialog-titlebar-restore").attr("role","button").mouseover(function(){a(this).addClass("ui-state-hover")}).mouseout(function(){a(this).removeClass("ui-state-hover")}).focus(function(){a(this).addClass("ui-state-focus")}).blur(function(){a(this).removeClass("ui-state-focus")}).end().find(".ui-dialog-titlebar-maximize").toggle(c.maximize).css({right:c.maximize?"1.4em":"-9999em"}).click(function(c){c.preventDefault();
a(b).dialogExtend("maximize")}).end().find(".ui-dialog-titlebar-minimize").toggle(c.minimize).css({right:c.maximize?"2.5em":c.minimize?"1.4em":"-9999em"}).click(function(c){c.preventDefault();a(b).dialogExtend("minimize")}).end().find(".ui-dialog-titlebar-restore").hide().css({right:"-9999em"}).click(function(c){c.preventDefault();a(b).dialogExtend("restore")}).end().dblclick(function(d){c.dblclick&&c.dblclick.length&&a(b).dialogExtend("normal"!=a(b).data("dialog-state")?"restore":c.dblclick)}).each(function(){a(this).select(function(){return!1})});
return b},_initEvents:function(){var b=this;a.each(c.events,function(d){a.isFunction(c.events[d])&&a(b).bind(d+".dialogExtend",c.events[d])});return b},_initStyles:function(){a('<style type="text/css">.ui-dialog .ui-dialog-titlebar-maximize,.ui-dialog .ui-dialog-titlebar-minimize,.ui-dialog .ui-dialog-titlebar-restore { position: absolute; top: 50%; width: 19px; margin: -10px 8px 0 0; padding: 1px; height: 18px; }.ui-dialog .ui-dialog-titlebar-maximize span,.ui-dialog .ui-dialog-titlebar-minimize span,.ui-dialog .ui-dialog-titlebar-restore span { display: block; margin: 1px; }.ui-dialog .ui-dialog-titlebar-maximize:hover,.ui-dialog .ui-dialog-titlebar-maximize:focus,.ui-dialog .ui-dialog-titlebar-minimize:hover,.ui-dialog .ui-dialog-titlebar-minimize:focus,.ui-dialog .ui-dialog-titlebar-restore:hover,.ui-dialog .ui-dialog-titlebar-restore:focus { padding: 0; }.ui-dialog .ui-dialog-titlebar ::selection { background-color: transparent; }</style>').appendTo("body");
return this},_initTitleBar:function(){switch(c.titlebar){case !1:break;case "none":if(a(this).dialog("option","draggable")){var b=a("<div />").addClass("ui-dialog-draggable-handle").css("cursor","move").height(5);a(this).dialog("widget").prepend(b).draggable("option","handle",b)}a(this).dialog("widget").find(".ui-dialog-titlebar").find(".ui-dialog-title").html("&nbsp;").end().css({"background-color":"transparent","background-image":"none",border:0,position:"absolute",right:0,top:0,"z-index":9999}).end();
break;case "transparent":a(this).dialog("widget").find(".ui-dialog-titlebar").css({"background-color":"transparent","background-image":"none",border:0});break;default:a.error("jQuery.dialogExtend Error : Invalid <titlebar> value '"+c.titlebar+"'")}return this},_loadSnapshot:function(){return{config:{resizable:a(this).data("original-config-resizable"),draggable:a(this).data("original-config-draggable")},size:{height:a(this).data("original-size-height"),width:a(this).data("original-size-width"),maxHeight:a(this).data("original-size-maxHeight")},
position:{mode:a(this).data("original-position-mode"),left:a(this).data("original-position-left"),top:a(this).data("original-position-top")},titlebar:{wrap:a(this).data("original-titlebar-wrap")}}},_restoreFromCollapsed:function(){var b=a(this).dialogExtend("_loadSnapshot");a(this).show().dialog("widget").find(".ui-dialog-buttonpane:hidden").show().end().find(".ui-dialog-titlebar").css("white-space",b.titlebar.wrap).end().find(".ui-dialog-content").dialog("option",{height:b.size.height,maxHeight:b.size.maxHeight});
return this},_restoreFromMaximized:function(){var b=a(this).dialogExtend("_loadSnapshot");a(this).dialog("widget").css("position",b.position.mode).find(".ui-dialog-titlebar").css("white-space",b.titlebar.wrap).end().find(".ui-dialog-content").dialog("option",{resizable:b.config.resizable,draggable:b.config.draggable,height:b.size.height,width:b.size.width,maxHeight:b.size.maxHeight,position:[b.position.left,b.position.top]}).dialog("widget").draggable("option","handle",a(this).find(".ui-dialog-draggable-handle")).find(".ui-dialog-draggable-handle").css("cursor",
"move");return this},_restoreFromMinimized:function(){a(this).dialogExtend("_loadSnapshot");a(this).dialog("widget").find(".ui-dialog-content").dialog("widget").draggable("option","handle",a(this).find(".ui-dialog-draggable-handle")).find(".ui-dialog-draggable-handle").css("cursor","move");return this},_saveSnapshot:function(){"normal"==a(this).data("dialog-state")&&a(this).data("original-config-resizable",a(this).dialog("option","resizable")).data("original-config-draggable",a(this).dialog("option",
"draggable")).data("original-size-height",a(this).dialog("widget").height()).data("original-size-width",a(this).dialog("option","width")).data("original-size-maxHeight",a(this).dialog("option","maxHeight")).data("original-position-mode",a(this).dialog("widget").css("position")).data("original-position-left",a(this).dialog("widget").offset().left).data("original-position-top",a(this).dialog("widget").offset().top).data("original-titlebar-wrap",a(this).dialog("widget").find(".ui-dialog-titlebar").css("white-space"));
return this},_toggleButtons:function(){a(this).dialog("widget").find(".ui-dialog-titlebar-maximize").toggle("maximized"!=a(this).data("dialog-state")&&c.maximize).end().find(".ui-dialog-titlebar-minimize").toggle("minimized"!=a(this).data("dialog-state")&&c.minimize).end().find(".ui-dialog-titlebar-restore").toggle("normal"!=a(this).data("dialog-state")&&(c.maximize||c.minimize)).css({right:"maximized"==a(this).data("dialog-state")?"24px":"minimized"==a(this).data("dialog-state")?c.maximize?"48px":
"24px":"-9999em"}).end();return this},_trigger:function(b){a(this).triggerHandler(b+".dialogExtend",this);return this},_verifySettings:function(){c.dblclick&&"maximize"!=c.dblclick&&"minimize"!=c.dblclick&&"collapse"!=c.dblclick&&(a.error("jQuery.dialogExtend Error : Invalid <dblclick> value '"+c.dblclick+"'"),c.dblclick=!1);c.titlebar&&"none"!=c.titlebar&&"transparent"!=c.titlebar&&(a.error("jQuery.dialogExtend Error : Invalid <titlebar> value '"+c.titlebar+"'"),c.titlebar=!1);return this}};a.fn.dialogExtend=
function(b){if(f[b])return f[b].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof b&&b)a.error("jQuery.dialogExtend Error : Method <"+b+"> does not exist");else return f.init.apply(this,arguments)}})(jQuery);
