(function(g){var c=[];var h=false;var a=[];var l={screenLockerBackground:"#000",screenLockerOpacity:"0.5"};g.setupJMPopups=function(m){l=jQuery.extend(l,m);return this};g.openPopupLayer=function(m){if(typeof(m.name)!="undefined"&&!j(m.name)){m=jQuery.extend({width:"auto",height:"auto",parameters:{},target:"",success:function(){},error:function(){},beforeClose:function(){},afterClose:function(){},reloadSuccess:null,cache:false},m);i(m,true);return this}};g.closePopupLayer=function(m){if(m){for(var n=0;n<c.length;n++){if(c[n].name==m){var o=c[n];c.splice(n,1);o.beforeClose();g("#popupLayer_"+m).fadeOut(function(){g("#popupLayer_"+m).remove();a.pop();if(a.length>0){g(a[a.length-1]).focus()}o.afterClose();k(m)});break}}}else{if(c.length>0){g.closePopupLayer(c[c.length-1].name)}}return this};g.reloadPopupLayer=function(m,o){if(m){for(var n=0;n<c.length;n++){if(c[n].name==m){if(o){c[n].reloadSuccess=o}i(c[n],false);break}}}else{if(c.length>0){g.reloadPopupLayer(c[c.length-1].name)}}return this};function d(){if(h){g("#popupLayerScreenLocker").height(g(document).height()+"px");g("#popupLayerScreenLocker").width(g(document.body).outerWidth(true)+"px")}}function j(m){if(m){for(var n=0;n<c.length;n++){if(c[n].name==m){return true}}}return false}function f(){if(g("#popupLayerScreenLocker").length){if(c.length==1){h=true;d();g("#popupLayerScreenLocker").fadeIn()}if(g.browser.msie&&g.browser.version<7){g("select:not(.hidden-by-jmp)").addClass("hidden-by-jmp hidden-by-"+c[c.length-1].name).css("visibility","hidden")}g("#popupLayerScreenLocker").css("z-index",parseInt(c.length==1?999:g("#popupLayer_"+c[c.length-2].name).css("z-index"))+1)}else{g("form").append("<div id='popupLayerScreenLocker'><!-- --></div>");g("#popupLayerScreenLocker").css({position:"absolute",background:l.screenLockerBackground,left:"0",top:"0",opacity:l.screenLockerOpacity,display:"none"});f();g("#popupLayerScreenLocker").click(function(){g.closePopupLayer()})}}function k(m){if(c.length==0){screenlocker=false;g("#popupLayerScreenLocker").fadeOut()}else{g("#popupLayerScreenLocker").css("z-index",parseInt(g("#popupLayer_"+c[c.length-1].name).css("z-index"))-1)}if(g.browser.msie&&g.browser.version<7){g("select.hidden-by-"+m).removeClass("hidden-by-jmp hidden-by-"+m).css("visibility","visible")}}function e(r,n){if(r){if(r.width()<g(window).width()){var q=(document.documentElement.offsetWidth-r.width())/2}else{var q=document.documentElement.scrollLeft+5}if(r.height()<g(window).height()){var p=document.documentElement.scrollTop+(g(window).height()-r.height())/2}else{var p=document.documentElement.scrollTop+5}var m={left:q+"px",top:p+"px"};if(!n){r.css(m)}else{r.animate(m,"slow")}d()}else{for(var o=0;o<c.length;o++){e(g("#popupLayer_"+c[o].name),true)}}}function b(m,s,r){var q="popupLayer_"+m.name;if(s){f();g("form").append("<div id='"+q+"'><!-- --></div>");var t=parseInt(c.length==1?1000:g("#popupLayer_"+c[c.length-2].name).css("z-index"))+2}else{var t=g("#"+q).css("z-index")}var u=g("#"+q);u.css({visibility:"hidden",width:m.width=="auto"?"":m.width+"px",height:m.height=="auto"?"":m.height+"px",position:"absolute","z-index":t});var p="<a href='#' class='jmp-link-at-top' style='position:absolute; left:-9999px; top:-1px;'>&nbsp;</a><input class='jmp-link-at-top' style='position:absolute; left:-9999px; top:-1px;' />";var n="<a href='#' class='jmp-link-at-bottom' style='position:absolute; left:-9999px; bottom:-1px;'>&nbsp;</a><input class='jmp-link-at-bottom' style='position:absolute; left:-9999px; top:-1px;' />";u.html(p+r+n);e(u);u.css("display","none");u.css("visibility","visible");if(s){u.fadeIn()}else{u.show()}g("#"+q+" .jmp-link-at-top, #"+q+" .jmp-link-at-bottom").focus(function(){g(a[a.length-1]).focus()});var o=g("#"+q+" a:visible:not(.jmp-link-at-top, .jmp-link-at-bottom), #"+q+" *:input:visible:not(.jmp-link-at-top, .jmp-link-at-bottom)");if(o.length==0){var v="<a href='#' class='jmp-link-inside-popup' style='position:absolute; left:-9999px;'>&nbsp;</a>";u.find(".jmp-link-at-top").after(v);a.push(g(u).find(".jmp-link-inside-popup")[0])}else{o.each(function(){if(!g(this).hasClass("jmp-link-at-top")&&!g(this).hasClass("jmp-link-at-bottom")){a.push(this);return false}})}g(a[a.length-1]).focus();m.success();if(m.reloadSuccess){m.reloadSuccess();m.reloadSuccess=null}}function i(m,n){if(n){c.push(m)}if(m.target!=""){b(m,n,g("#"+m.target).html())}else{g.ajax({url:m.url,data:m.parameters,cache:m.cache,dataType:"html",method:"GET",success:function(o){b(m,n,o)},error:m.error})}}g(window).resize(function(){d();e()});g(document).keydown(function(m){if(m.keyCode==27){g.closePopupLayer()}})})(jQuery);
