(function(a){var d=a.browser.msie&&parseInt(a.browser.version)==6&&typeof window.XMLHttpRequest!="object",c=null,b=[];a.modal=function(c,b){return a.modal.impl.init(c,b)};a.modal.close=function(){a.modal.impl.close()};a.fn.modal=function(b){return a.modal.impl.init(this,b)};a.modal.defaults={appendTo:"body",focus:true,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:200,minWidth:300,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1e3,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:"simplemodal-close",escClose:true,overlayClose:false,position:null,persist:false,onOpen:null,onShow:null,onClose:null};a.modal.impl={o:null,d:{},init:function(d,e){var b=this;if(b.d.data)return false;c=a.browser.msie&&!a.boxModel;b.o=a.extend({},a.modal.defaults,e);b.zIndex=b.o.zIndex;b.occb=false;if(typeof d=="object"){d=d instanceof jQuery?d:a(d);if(d.parent().parent().size()>0){b.d.parentNode=d.parent();if(!b.o.persist)b.d.orig=d.clone(true)}}else if(typeof d=="string"||typeof d=="number")d=a("<div></div>").html(d);else{alert("SimpleModal Error: Unsupported data type: "+typeof d);return b}b.create(d);d=null;b.open();a.isFunction(b.o.onShow)&&b.o.onShow.apply(b,[b.d]);return b},create:function(f){var e=this;b=e.getDimensions();if(d)e.d.iframe=a('<iframe src="javascript:false;"></iframe>').css(a.extend(e.o.iframeCss,{display:"none",opacity:0,position:"fixed",height:b[0],width:b[1],zIndex:e.o.zIndex,top:0,left:0})).appendTo(e.o.appendTo);e.d.overlay=a("<div></div>").attr("id",e.o.overlayId).addClass("simplemodal-overlay").css(a.extend(e.o.overlayCss,{display:"none",opacity:e.o.opacity/100,height:b[0],width:b[1],position:"fixed",left:0,top:0,zIndex:e.o.zIndex+1})).appendTo(e.o.appendTo);e.d.container=a("<div></div>").attr("id",e.o.containerId).addClass("simplemodal-container").css(a.extend(e.o.containerCss,{display:"none",position:"fixed",zIndex:e.o.zIndex+2})).append(e.o.close&&e.o.closeHTML?a(e.o.closeHTML).addClass(e.o.closeClass):"").appendTo(e.o.appendTo);e.d.wrap=a("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(e.d.container);e.d.data=f.attr("id",f.attr("id")||e.o.dataId).addClass("simplemodal-data").css(a.extend(e.o.dataCss,{display:"none"})).appendTo("body");f=null;e.setContainerDimensions();e.d.data.appendTo(e.d.wrap);(d||c)&&e.fixIE()},bindEvents:function(){var e=this;a("."+e.o.closeClass).bind("click.simplemodal",function(a){a.preventDefault();e.close()});e.o.close&&e.o.overlayClose&&e.d.overlay.bind("click.simplemodal",function(a){a.preventDefault();e.close()});a(document).bind("keydown.simplemodal",function(a){if(e.o.focus&&a.keyCode==9)e.watchTab(a);else if(e.o.close&&e.o.escClose&&a.keyCode==27){a.preventDefault();e.close()}});a(window).bind("resize.simplemodal",function(){b=e.getDimensions();e.setContainerDimensions(true);if(d||c)e.fixIE();else{e.d.iframe&&e.d.iframe.css({height:b[0],width:b[1]});e.d.overlay.css({height:b[0],width:b[1]})}})},unbindEvents:function(){a("."+this.o.closeClass).unbind("click.simplemodal");a(document).unbind("keydown.simplemodal");a(window).unbind("resize.simplemodal");this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var c=this,b=c.o.position;a.each([c.d.iframe||null,c.d.overlay,c.d.container],function(r,k){if(k){var e="document.body.clientHeight",f="document.body.clientWidth",n="document.body.scrollHeight",h="document.body.scrollLeft",i="document.body.scrollTop",o="document.body.scrollWidth",p="document.documentElement.clientHeight",q="document.documentElement.clientWidth",c="document.documentElement.scrollLeft",d="document.documentElement.scrollTop",a=k[0].style;a.position="absolute";if(r<2){a.removeExpression("height");a.removeExpression("width");a.setExpression("height",""+n+" > "+e+" ? "+n+" : "+e+' + "px"');a.setExpression("width",""+o+" > "+f+" ? "+o+" : "+f+' + "px"')}else{var m,l;if(b&&b.constructor==Array){var j=b[0]?typeof b[0]=="number"?b[0].toString():b[0].replace(/px/,""):k.css("top").replace(/px/,"");m=j.indexOf("%")==-1?j+" + (t = "+d+" ? "+d+" : "+i+') + "px"':parseInt(j.replace(/%/,""))+" * (("+p+" || "+e+") / 100) + (t = "+d+" ? "+d+" : "+i+') + "px"';if(b[1]){var g=typeof b[1]=="number"?b[1].toString():b[1].replace(/px/,"");l=g.indexOf("%")==-1?g+" + (t = "+c+" ? "+c+" : "+h+') + "px"':parseInt(g.replace(/%/,""))+" * (("+q+" || "+f+") / 100) + (t = "+c+" ? "+c+" : "+h+') + "px"'}}else{m="("+p+" || "+e+") / 2 - (this.offsetHeight / 2) + (t = "+d+" ? "+d+" : "+i+') + "px"';l="("+q+" || "+f+") / 2 - (this.offsetWidth / 2) + (t = "+c+" ? "+c+" : "+h+') + "px"'}a.removeExpression("top");a.removeExpression("left");a.setExpression("top",m);a.setExpression("left",l)}}})},focus:function(d){var c=this,e=d||"first",b=a(":input:enabled:visible:"+e,c.d.wrap);b.length>0?b.focus():c.d.wrap.focus()},getDimensions:function(){var b=a(window),c=a.browser.opera&&a.browser.version>"9.5"&&a.fn.jquery<="1.2.6"?document.documentElement.clientHeight:a.browser.opera&&a.browser.version<"9.5"&&a.fn.jquery>"1.2.6"?window.innerHeight:b.height();return[c,b.width()]},getVal:function(a){return a=="auto"?0:a.indexOf("%")>0?a:parseInt(a.replace(/px/,""))},setContainerDimensions:function(i){var a=this;if(!i||i&&a.o.autoResize){var c=a.getVal(a.d.container.css("height")),d=a.getVal(a.d.container.css("width")),e=a.d.data.outerHeight(true),f=a.d.data.outerWidth(true),g=a.o.maxHeight&&a.o.maxHeight<b[0]?a.o.maxHeight:b[0],h=a.o.maxWidth&&a.o.maxWidth<b[1]?a.o.maxWidth:b[1];if(!c)if(!e)c=a.o.minHeight;else if(e>g)c=g;else if(e<a.o.minHeight)c=a.o.minHeight;else c=e;else c=c>g?g:c;if(!d)if(!f)d=a.o.minWidth;else if(f>h)d=h;else if(f<a.o.minWidth)d=a.o.minWidth;else d=f;else d=d>h?h:d;a.d.container.css({height:c,width:d});(e>c||f>d)&&a.d.wrap.css({overflow:"auto"})}a.o.autoPosition&&a.setPosition()},setPosition:function(){var a=this,d,c,e=b[0]/2-a.d.container.outerHeight(true)/2,f=b[1]/2-a.d.container.outerWidth(true)/2;if(a.o.position&&Object.prototype.toString.call(a.o.position)==="[object Array]"){d=a.o.position[0]||e;c=a.o.position[1]||f}else{d=e;c=f}a.d.container.css({left:c,top:d})},watchTab:function(b){var c=this;if(a(b.target).parents(".simplemodal-container").length>0){c.inputs=a(":input:enabled:visible:first, :input:enabled:visible:last",c.d.data[0]);if(!b.shiftKey&&b.target==c.inputs[c.inputs.length-1]||b.shiftKey&&b.target==c.inputs[0]||c.inputs.length==0){b.preventDefault();var d=b.shiftKey?"last":"first";setTimeout(function(){c.focus(d)},10)}}else{b.preventDefault();setTimeout(function(){c.focus()},10)}},open:function(){var b=this;b.d.iframe&&b.d.iframe.show();if(a.isFunction(b.o.onOpen))b.o.onOpen.apply(b,[b.d]);else{b.d.overlay.show();b.d.container.show();b.d.data.show()}b.focus();b.bindEvents()},close:function(){var b=this;if(!b.d.data)return false;b.unbindEvents();if(a.isFunction(b.o.onClose)&&!b.occb){b.occb=true;b.o.onClose.apply(b,[b.d])}else{if(b.d.parentNode)if(b.o.persist)b.d.data.hide().appendTo(b.d.parentNode);else{b.d.data.hide().remove();b.d.orig.appendTo(b.d.parentNode)}else b.d.data.hide().remove();b.d.container.hide().remove();b.d.overlay.hide().remove();b.d.iframe&&b.d.iframe.hide().remove();b.d={}}}}})(jQuery)
