(function($){var isIE6=$.browser.msie&&$.browser.version==6.0;var JOVERLAY_TIMER=null;var JOVERLAY_ELEMENT_PREV=null;$.fn.jOverlay=function(options){if($('#jOverlay').length){$.closeOverlay();}
JOVERLAY_ELEMENT_PREV=null;if(JOVERLAY_TIMER!==null){clearTimeout(JOVERLAY_TIMER);}
var options=$.extend({},$.fn.jOverlay.options,options);function center(id){if(options.center){$.center(id);}}
var element=this.is('*')?this:'#jOverlayContent';var position=isIE6?'absolute':'fixed';var isImage=/([^\/\\]+)\.(png|gif|jpeg|jpg|bmp)$/i.test(options.url);var imgLoading=options.imgLoading?"<img id='jOverlayLoading' src='"+options.imgLoading+"' style='position:"+position+"; z-index:"+(options.zIndex+9)+";'/>":'';$('body').prepend(imgLoading+"<div id='jOverlay' />"
+"<div id='jOverlayContent' style='position:"+position+"; z-index:"+(options.zIndex+5)+"; display:none;'/>");$('#jOverlayLoading').load(function(){center(this);});if(isIE6){$('select').hide();$('#jOverlayContent select').show();}
$('#jOverlay').css({backgroundColor:options.color,position:position,top:'0px',left:'0px',filter:'alpha(opacity='+(options.opacity*100)+')',opacity:options.opacity,zIndex:options.zIndex,width:!isIE6?'100%':$(window).width()+'px',height:!isIE6?'100%':$(document).height()+'px'}).show();if(this.is('*')){JOVERLAY_ELEMENT_PREV=this.prev();$('#jOverlayContent').html(this.show().attr('display',options.autoHide?'none':this.css('display')));if(!isImage){center('#jOverlayContent');$('#jOverlayContent').show();if(!options.url&&$.isFunction(options.success)){options.success(this);}}}
if(isImage){$('<img/>').load(function(){var resize=$.resize(this.width,this.height);$(this).css({width:resize.width,height:resize.height});$(element).html(this);center('#jOverlayContent');$('#jOverlayLoading').fadeOut(500);$('#jOverlayContent').show();if($.isFunction(options.success)){options.success(this);}}).error(function(){alert('Image ('+options.url+') not found.');$.closeOverlay();}).attr({'src':options.url,'alt':options.url});}
if(options.url&&!isImage){$.ajax({type:options.method,data:options.data,url:options.url,success:function(responseText){$('#jOverlayLoading').fadeOut(500);$(element).html(responseText).show();center('#jOverlayContent');if($.isFunction(options.success)){options.success(responseText);}},error:function(){alert('URL ('+options.url+') not found.');$.closeOverlay();}});}
if(isIE6){$(window).scroll(function(){center('#jOverlayContent');});$(window).resize(function(){$('#jOverlay').css({width:$(window).width()+'px',height:$(document).height()+'px'});center('#jOverlayContent');});}
$(document).keydown(function(event){if(event.keyCode==27){$.closeOverlay();}});if(options.bgClickToClose){$('#jOverlay').click($.closeOverlay);}
if(Number(options.timeout)>0){jOverlayTimer=setTimeout($.closeOverlay,Number(options.timeout));}
$('#jOverlayContent').css(options.css||{});};$.resize=function(imageWidth,imageHeight){var x=$(window).width()-150;var y=$(window).height()-150;if(imageWidth>x){imageHeight=imageHeight*(x/imageWidth);imageWidth=x;if(imageHeight>y){imageWidth=imageWidth*(y/imageHeight);imageHeight=y;}}else if(imageHeight>y){imageWidth=imageWidth*(y/imageHeight);imageHeight=y;if(imageWidth>x){imageHeight=imageHeight*(x/imageWidth);imageWidth=x;}}
return{width:imageWidth,height:imageHeight};};$.center=function(element){var element=$(element);var elemWidth=element.width();var elemHeight=element.height();element.css({width:elemWidth+'px',height:elemHeight+'px',marginLeft:'-'+(elemWidth/2)+'px',marginTop:'-'+(elemHeight/2)+'px',top:'50%',left:'50%'});};$.fn.jOverlay.options={method:'GET',data:'',url:'',color:'#000',opacity:'0.6',zIndex:9999,center:true,imgLoading:'',bgClickToClose:true,success:null,timeout:0,autoHide:true,css:{}};$.closeOverlay=function(){if(isIE6){$("select").show();}
if(JOVERLAY_ELEMENT_PREV!==null){if(JOVERLAY_ELEMENT_PREV!==null){var element=$('#jOverlayContent').children();JOVERLAY_ELEMENT_PREV.after(element.css('display',element.attr('display')));element.removeAttr('display');}}
$('#jOverlayLoading, #jOverlayContent, #jOverlay').remove();};})(jQuery);