/*
 * jQuery UI Dialog 1.8.1
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Dialog
 *
 * Depends:
 *	jquery.ui.core.js
 *	jquery.ui.widget.js
 *  jquery.ui.button.js
 *	jquery.ui.draggable.js
 *	jquery.ui.mouse.js
 *	jquery.ui.position.js
 *	jquery.ui.resizable.js
 */

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