
(function($){$.tools=$.tools||{version:'@VERSION'};var tool;tool=$.tools.expose={conf:{maskId:'exposeMask',loadSpeed:'slow',closeSpeed:'fast',closeOnClick:true,closeOnEsc:true,zIndex:9998,opacity:0.8,startOpacity:0,color:'#fff',onLoad:null,onClose:null}};function viewport(){if($.browser.msie){var d=$(document).height(),w=$(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,d-w<20?w:d];}
return[$(document).width(),$(document).height()];}
function call(fn){if(fn){return fn.call($.mask);}}
var mask,exposed,loaded,config,overlayIndex;$.mask={load:function(conf,els){if(loaded){return this;}
if(typeof conf=='string'){conf={color:conf};}
conf=conf||config;config=conf=$.extend($.extend({},tool.conf),conf);mask=$("#"+conf.maskId);if(!mask.length){mask=$('<div/>').attr("id",conf.maskId);$("body").append(mask);}
var size=viewport();mask.css({position:'absolute',top:0,left:0,width:size[0],height:size[1],display:'none',opacity:conf.startOpacity,zIndex:conf.zIndex});if(conf.color){mask.css("backgroundColor",conf.color);}
if(call(conf.onBeforeLoad)===false){return this;}
if(conf.closeOnEsc){$(document).bind("keydown.mask",function(e){if(e.keyCode==27){$.mask.close(e);}});}
if(conf.closeOnClick){mask.bind("click.mask",function(e){$.mask.close(e);});}
$(window).bind("resize.mask",function(){$.mask.fit();});if(els&&els.length){overlayIndex=els.eq(0).css("zIndex");$.each(els,function(){var el=$(this);if(!/relative|absolute|fixed/i.test(el.css("position"))){el.css("position","relative");}});exposed=els.css({zIndex:Math.max(conf.zIndex+1,overlayIndex=='auto'?0:overlayIndex)});}
mask.css({display:'block'}).fadeTo(conf.loadSpeed,conf.opacity,function(){$.mask.fit();call(conf.onLoad);});loaded=true;return this;},close:function(){if(loaded){if(call(config.onBeforeClose)===false){return this;}
mask.fadeOut(config.closeSpeed,function(){call(config.onClose);if(exposed){exposed.css({zIndex:overlayIndex});}});$(document).unbind("keydown.mask");mask.unbind("click.mask");$(window).unbind("resize.mask");loaded=false;}
return this;},fit:function(){if(loaded){var size=viewport();mask.css({width:size[0],height:size[1]});}},getMask:function(){return mask;},isLoaded:function(){return loaded;},getConf:function(){return config;},getExposed:function(){return exposed;}};$.fn.mask=function(conf){$.mask.load(conf);return this;};$.fn.expose=function(conf){$.mask.load(conf,this);return this;};})(jQuery);
