(function(c){"object"===typeof module&&"object"===typeof module.exports?module.exports=c(require("jquery")):c(jQuery)})(function(c){c.fn.jqm=function(a){return this.each(function(){var b=c(this).data("jqm")||c.extend({ID:n++},c.jqm.params);b=c.extend(b,a);c(this).data("jqm",b).addClass("jqm-init")[0]._jqmID=b.ID;c(this).jqmAddTrigger(b.trigger)})};c.fn.jqmAddTrigger=function(a){if(a)return this.each(function(){k(c(this),"jqmShow",a)||window.console&&window.console.error&&window.console.error("jqmAddTrigger must be called on initialized modals")})};
c.fn.jqmAddClose=function(a){if(a)return this.each(function(){k(c(this),"jqmHide",a)||window.console&&window.console.error&&window.console.error("jqmAddClose must be called on initialized modals")})};c.fn.jqmShow=function(a){return this.each(function(){this._jqmShown||p(c(this),a)})};c.fn.jqmHide=function(a){return this.each(function(){if(this._jqmShown){var b=c(this),d=a;d=d||window.event;var e=b.data("jqm");b={w:b,c:e,o:b.data("jqmv"),t:d};d=b.w;e=b.o;var f=b.c;!1!==f.onHide(b)&&(d[0]._jqmShown=
!1,f.modal&&(h.pop(),h[0]||l("unbind")),f.toTop&&e&&c("#jqmP"+f.ID).after(d).remove())}})};var p=function(a,b){b=b||window.event;var d=a.data("jqm"),e=parseInt(a.css("z-index"),10)||3E3,f=c("<div></div>").addClass(d.overlayClass).css({height:"100%",width:"100%",position:"fixed",left:0,top:0,"z-index":e-1,opacity:d.overlay/100}),m={w:a,c:d,o:f,t:b};a.css("z-index",e);if(d.ajax){var g=d.target||a;e=d.ajax;g="string"===typeof g?c(g,a):c(g);"@"===e.substr(0,1)&&(e=c(b).attr(e.substring(1)));g.load(e,
function(){d.onLoad&&d.onLoad.call(this,m);d.closeClass&&a.jqmAddClose(c("."+d.closeClass,g||a))});d.ajaxText&&g.html(d.ajaxText)}q(m)},k=function(a,b,d){var e=a.data("jqm");if(e)return c(d).each(function(){this[b]=this[b]||[];0>c.inArray(e.ID,this[b])&&(this[b].push(e.ID),c(this).on("click",function(f){if(!f.isDefaultPrevented())a[b](this);return!1}))})},q=function(a){var b=a.w,d=a.o,e=a.c;!1!==e.onShow(a)&&(b[0]._jqmShown=!0,e.modal?(h[0]||l("bind"),h.push(b[0])):b.jqmAddClose(d),e.closeClass&&
b.jqmAddClose(c("."+e.closeClass,b)),e.toTop&&d&&b.before('<span id="jqmP'+e.ID+'"></span>').insertAfter(d),b.data("jqmv",d),b.off("keydown",c.jqm.closeOnEscFunc),e.closeOnEsc&&b.attr("tabindex",0).bind("keydown",c.jqm.closeOnEscFunc).focus())},l=function(a){c(document)[a]("keypress keydown mousedown",r)},r=function(a){var b=c(a.target).data("jqm")||c(a.target).parents(".jqm-init:first").data("jqm"),d=h[h.length-1];return b&&b.ID===d._jqmID?!0:c.jqm.focusFunc(d,a)},n=0,h=[];c.jqm={params:{overlay:50,
overlayClass:"jqmOverlay",closeClass:"jqmClose",closeOnEsc:!1,trigger:".jqModal",ajax:!1,target:!1,ajaxText:"",modal:!1,toTop:!1,onShow:function(a){0<a.c.overlay&&a.o.prependTo("body");a.w.show();c.jqm.focusFunc(a.w,!0);return!0},onHide:function(a){a.w.hide()&&a.o&&a.o.remove();return!0},onLoad:!1},focusFunc:function(a,b){b&&c(":input:visible:first",a).focus();return!1},closeOnEscFunc:function(a){if(27===a.keyCode)return c(this).jqmHide(),!1}};return c.jqm});
