/* Copyright (c) 2009 Alvaro A. Lima Jr http://alvarojunior.com/jquery/joverlay.html
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * Version: 0.4 (Abr 20, 2009)
 * Requires: jQuery 1.3+
 */
(function($){var j=$.browser.msie&&parseInt($.browser.version)==6;$.fn.jOverlay=function(c){var c=$.extend({},$.fn.jOverlay.options,c);var d=c.imgLoading?"<img id='jOverlayLoading' src='"+c.imgLoading+"' />":'';var e=d+"<div id='jOverlay'></div><div id='jOverlayContent' style='display:none;'></div>";e=j?"<iframe id='jOverlayIframe'></iframe>"+e:e;var f=$(window).width();var g=$(document).height();var h=j?'absolute':'fixed';var i=this.is('*')?this.clone():null;$('body').prepend(e);$('#jOverlayLoading').css({position:h,zIndex:c.zIndex+50}).load(function(){if(c.center){$.center(this)}});$('#jOverlayContent').css({position:h,zIndex:c.zIndex+1}).show();if(this.is('*')){this.hide();$('#jOverlayContent').css({height:this.height(),width:this.width()}).html(i.addClass('jOverlayClone').css('display','block')).show();if(c.center){$.center('#jOverlayContent')}}if(this.is('*')&&c.url){$("#jOverlayContent .jOverlayClone").load(c.url,c.data,function(a){$('#jOverlayLoading').fadeOut(600);c.success(a)})}else{if(c.url){$.ajax({type:c.method,data:c.data,url:c.url,success:function(a){$('#jOverlayLoading').fadeOut(600);$("#jOverlayContent").html(a).show();if(c.center){$.center("#jOverlayContent")}c.success(a)}})}else if(!this.is('*')){$('#jOverlayContent').html("<div style='background:#FFF;'>Element not found!<br/>Press ESC!</div>")}else{$('#jOverlayLoading').fadeOut(600);$("#jOverlayContent").show();c.success(i.html())}}if(j){$('#jOverlayIframe').css({backgroundColor:'#FFF',border:'none',filter:'alpha(opacity=0)',opacity:0,position:'absolute',top:'0px',left:'0px',zIndex:c.zIndex-5,width:f+'px',height:g+'px'}).show()}$('#jOverlay').css({backgroundColor:c.color,position:h,top:'0px',left:'0px',filter:'alpha(opacity='+(c.opacity*100)+')',opacity:c.opacity,zIndex:c.zIndex,width:f+'px',height:!j?$(window).height()+'px':g+'px'}).show('fast');if(c.bgClickToClose){$('#jOverlay').click($.closeOverlay)}if(j){$(window).scroll(function(){if(c.center){$.center('#jOverlayContent')}})}$(window).resize(function(){var a=$(window).width();var b=$(document).height();if(j){$('#jOverlayIframe').css({width:a+'px',height:b+'px'})}$('#jOverlay').css({width:a+'px',height:b+'px'});if(c.center){$.center('#jOverlayContent')}});$(document).keydown(function(a){if(a.keyCode==27){$.closeOverlay()}})};$.center=function(a){var a=$(a);var b=a.height();var c=a.width();var d=$(window).width();var e=$(window).height();var f=$(window).scrollLeft();var g=$(window).scrollTop();var h=(f+Math.floor((d-c)/2));var i=(g+Math.floor((e-b)/2));var t=i-g;var l=h-f;if(j){t=((i!=null&&i>0)?i:'0');l=((h!=null&&h>0)?h:'0')}a.css({top:t+'px',left:l+'px'})};$.fn.jOverlay.options={method:'GET',data:'',url:'',color:'#000',opacity:'0.6',zIndex:9999,center:true,imgLoading:'',bgClickToClose:true,success:function(a){return null}};$.closeOverlay=function(){$('#jOverlayLoading, #jOverlayContent, #jOverlayIframe, #jOverlay').remove()}})(jQuery);
