(function(C){var B=C.browser.msie&&parseInt(C.browser.version)==6&&typeof window.XMLHttpRequest!="object",D=null,A=[];C.modal=function(F,E){return C.modal.impl.init(F,E)};C.modal.close=function(){C.modal.impl.close()};C.fn.modal=function(E){return C.modal.impl.init(this,E)};C.modal.defaults={appendTo:"form",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:1000,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};C.modal.impl={o:null,d:{},init:function(G,E){var F=this;if(F.d.data){return false}D=C.browser.msie&&!C.boxModel;F.o=C.extend({},C.modal.defaults,E);F.zIndex=F.o.zIndex;F.occb=false;if(typeof G=="object"){G=G instanceof jQuery?G:C(G);if(G.parent().parent().size()>0){F.d.parentNode=G.parent();if(!F.o.persist){F.d.orig=G.clone(true)}}}else{if(typeof G=="string"||typeof G=="number"){G=C("<div></div>").html(G)}else{alert("SimpleModal Error: Unsupported data type: "+typeof G);return F}}F.create(G);G=null;F.open();if(C.isFunction(F.o.onShow)){F.o.onShow.apply(F,[F.d])}return F},create:function(F){var E=this;A=E.getDimensions();if(B){E.d.iframe=C('<iframe src="javascript:false;"></iframe>').css(C.extend(E.o.iframeCss,{display:"none",opacity:0,position:"fixed",height:A[0],width:A[1],zIndex:E.o.zIndex,top:0,left:0})).appendTo(E.o.appendTo)}E.d.overlay=C("<div></div>").attr("id",E.o.overlayId).addClass("simplemodal-overlay").css(C.extend(E.o.overlayCss,{display:"none",opacity:E.o.opacity/100,height:A[0],width:A[1],position:"fixed",left:0,top:0,zIndex:E.o.zIndex+1})).appendTo(E.o.appendTo);E.d.container=C("<div></div>").attr("id",E.o.containerId).addClass("simplemodal-container").css(C.extend(E.o.containerCss,{display:"none",position:"fixed",zIndex:E.o.zIndex+2})).append(E.o.close&&E.o.closeHTML?C(E.o.closeHTML).addClass(E.o.closeClass):"").appendTo(E.o.appendTo);E.d.wrap=C("<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(C.extend(E.o.dataCss,{display:"none"})).appendTo("form");F=null;E.setContainerDimensions();E.d.data.appendTo(E.d.wrap);if(B||D){E.fixIE()}},bindEvents:function(){var E=this;C("."+E.o.closeClass).bind("click.simplemodal",function(F){F.preventDefault();E.close()});if(E.o.close&&E.o.overlayClose){E.d.overlay.bind("click.simplemodal",function(F){F.preventDefault();E.close()})}C(document).bind("keydown.simplemodal",function(F){if(E.o.focus&&F.keyCode==9){E.watchTab(F)}else{if((E.o.close&&E.o.escClose)&&F.keyCode==27){F.preventDefault();E.close()}}});C(window).bind("resize.simplemodal",function(){A=E.getDimensions();E.setContainerDimensions(true);if(B||D){E.fixIE()}else{E.d.iframe&&E.d.iframe.css({height:A[0],width:A[1]});E.d.overlay.css({height:A[0],width:A[1]})}})},unbindEvents:function(){C("."+this.o.closeClass).unbind("click.simplemodal");C(document).unbind("keydown.simplemodal");C(window).unbind("resize.simplemodal");this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var E=this,F=E.o.position;C.each([E.d.iframe||null,E.d.overlay,E.d.container],function(Q,J){if(J){var O="document.body.clientHeight",S="document.body.clientWidth",U="document.body.scrollHeight",R="document.body.scrollLeft",M="document.body.scrollTop",I="document.body.scrollWidth",H="document.documentElement.clientHeight",P="document.documentElement.clientWidth",N="document.documentElement.scrollLeft",V="document.documentElement.scrollTop",W=J[0].style;W.position="absolute";if(Q<2){W.removeExpression("height");W.removeExpression("width");W.setExpression("height",""+U+" > "+O+" ? "+U+" : "+O+' + "px"');W.setExpression("width",""+I+" > "+S+" ? "+I+" : "+S+' + "px"')}else{var L,G;if(F&&F.constructor==Array){var T=F[0]?typeof F[0]=="number"?F[0].toString():F[0].replace(/px/,""):J.css("top").replace(/px/,"");L=T.indexOf("%")==-1?T+" + (t = "+V+" ? "+V+" : "+M+') + "px"':parseInt(T.replace(/%/,""))+" * (("+H+" || "+O+") / 100) + (t = "+V+" ? "+V+" : "+M+') + "px"';if(F[1]){var K=typeof F[1]=="number"?F[1].toString():F[1].replace(/px/,"");G=K.indexOf("%")==-1?K+" + (t = "+N+" ? "+N+" : "+R+') + "px"':parseInt(K.replace(/%/,""))+" * (("+P+" || "+S+") / 100) + (t = "+N+" ? "+N+" : "+R+') + "px"'}}else{L="("+H+" || "+O+") / 2 - (this.offsetHeight / 2) + (t = "+V+" ? "+V+" : "+M+') + "px"';G="("+P+" || "+S+") / 2 - (this.offsetWidth / 2) + (t = "+N+" ? "+N+" : "+R+') + "px"'}W.removeExpression("top");W.removeExpression("left");W.setExpression("top",L);W.setExpression("left",G)}}})},focus:function(H){var F=this,G=H||"first";var E=C(":input:enabled:visible:"+G,F.d.wrap);E.length>0?E.focus():F.d.wrap.focus()},getDimensions:function(){var F=C(window);var E=C.browser.opera&&C.browser.version>"9.5"&&C.fn.jquery<="1.2.6"?document.documentElement.clientHeight:C.browser.opera&&C.browser.version<"9.5"&&C.fn.jquery>"1.2.6"?window.innerHeight:F.height();return[E,F.width()]},getVal:function(E){return E=="auto"?0:E.indexOf("%")>0?E:parseInt(E.replace(/px/,""))},setContainerDimensions:function(H){var J=this;if(!H||(H&&J.o.autoResize)){var I=J.getVal(J.d.container.css("height")),E=J.getVal(J.d.container.css("width")),K=J.d.data.outerHeight(true),G=J.d.data.outerWidth(true);var F=J.o.maxHeight&&J.o.maxHeight<A[0]?J.o.maxHeight:A[0],L=J.o.maxWidth&&J.o.maxWidth<A[1]?J.o.maxWidth:A[1];if(!I){if(!K){I=J.o.minHeight}else{if(K>F){I=F}else{if(K<J.o.minHeight){I=J.o.minHeight}else{I=K}}}}else{I=I>F?F:I}if(!E){if(!G){E=J.o.minWidth}else{if(G>L){E=L}else{if(G<J.o.minWidth){E=J.o.minWidth}else{E=G}}}}else{E=E>L?L:E}J.d.container.css({height:I,width:E});if(K>I||G>E){J.d.wrap.css({overflow:"visible"})}}if(J.o.autoPosition){J.setPosition()}},setPosition:function(){var F=this,H,G,I=(A[0]/2)-(F.d.container.outerHeight(true)/2),E=(A[1]/2)-(F.d.container.outerWidth(true)/2);if(F.o.position&&Object.prototype.toString.call(F.o.position)==="[object Array]"){H=F.o.position[0]||I;G=F.o.position[1]||E}F.d.container.css({left:G,top:H})},watchTab:function(F){var E=this;if(C(F.target).parents(".simplemodal-container").length>0){E.inputs=C(":input:enabled:visible:first, :input:enabled:visible:last",E.d.data[0]);if((!F.shiftKey&&F.target==E.inputs[E.inputs.length-1])||(F.shiftKey&&F.target==E.inputs[0])||E.inputs.length==0){F.preventDefault();var G=F.shiftKey?"last":"first";setTimeout(function(){E.focus(G)},10)}}else{F.preventDefault();setTimeout(function(){E.focus()},10)}},open:function(){var E=this;E.d.iframe&&E.d.iframe.show();if(C.isFunction(E.o.onOpen)){E.o.onOpen.apply(E,[E.d])}else{E.d.overlay.show();E.d.container.show();E.d.data.show()}E.focus();E.bindEvents()},close:function(){var E=this;if(!E.d.data){return false}E.unbindEvents();if(C.isFunction(E.o.onClose)&&!E.occb){E.occb=true;E.o.onClose.apply(E,[E.d])}else{if(E.d.parentNode){if(E.o.persist){E.d.data.hide().appendTo(E.d.parentNode)}else{E.d.data.hide().remove();E.d.orig.appendTo(E.d.parentNode)}}else{E.d.data.hide().remove()}E.d.container.hide().remove();E.d.overlay.hide().remove();E.d.iframe&&E.d.iframe.hide().remove();E.d={}}}}})(jQuery);