
(function($){$.tools=$.tools||{};$.tools.expose={version:'1.0.5',conf:{maskId:null,loadSpeed:'slow',closeSpeed:'fast',closeOnClick:true,closeOnEsc:true,zIndex:9998,opacity:0.8,color:'#456',api:false}};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[$(window).width(),$(document).height()];}
function Expose(els,conf){var self=this,$self=$(this),mask=null,loaded=false,origIndex=0;$.each(conf,function(name,fn){if($.isFunction(fn)){$self.bind(name,fn);}});$(window).resize(function(){self.fit();});$.extend(this,{getMask:function(){return mask;},getExposed:function(){return els;},getConf:function(){return conf;},isLoaded:function(){return loaded;},load:function(){if(loaded){return self;}
origIndex=els.eq(0).css("zIndex");if(conf.maskId){mask=$("#"+conf.maskId);}
if(!mask||!mask.length){var size=viewport();mask=$('<div/>').css({position:'absolute',top:0,left:0,width:size[0],height:size[1],display:'none',opacity:0,zIndex:conf.zIndex});if(conf.maskId){mask.attr("id",conf.maskId);}
$("body").append(mask);var bg=mask.css("backgroundColor");if(!bg||bg=='transparent'||bg=='rgba(0, 0, 0, 0)'){mask.css("backgroundColor",conf.color);}
if(conf.closeOnEsc){$(document).bind("keydown.unexpose",function(evt){if(evt.keyCode==27){self.close();}});}
if(conf.closeOnClick){mask.bind("click.unexpose",function(){self.close();});}}
var e=$.Event("onBeforeLoad");$self.trigger(e);if(e.isDefaultPrevented()){return self;}
$.each(els,function(){var el=$(this);if(!/relative|absolute|fixed/i.test(el.css("position"))){el.css("position","relative");}});els.css({zIndex:Math.max(conf.zIndex+1,origIndex=='auto'?0:origIndex)});var h=mask.height();if(!this.isLoaded()){mask.css({opacity:0,display:'block'}).fadeTo(conf.loadSpeed,conf.opacity,function(){if(mask.height()!=h){mask.css("height",h);}
$self.trigger("onLoad");});}
loaded=true;return self;},close:function(){if(!loaded){return self;}
var e=$.Event("onBeforeClose");$self.trigger(e);if(e.isDefaultPrevented()){return self;}
mask.fadeOut(conf.closeSpeed,function(){$self.trigger("onClose");els.css({zIndex:$.browser.msie?origIndex:null});});loaded=false;return self;},fit:function(){if(mask){var size=viewport();mask.css({width:size[0],height:size[1]});}},bind:function(name,fn){$self.bind(name,fn);return self;},onBeforeLoad:function(fn){return this.bind("onBeforeLoad",fn);},onLoad:function(fn){return this.bind("onLoad",fn);},onBeforeClose:function(fn){return this.bind("onBeforeClose",fn);},onClose:function(fn){return this.bind("onClose",fn);},unbind:function(name){$self.unbind(name);return self;}});}
$.fn.expose=function(conf){var el=this.eq(typeof conf=='number'?conf:0).data("expose");if(el){return el;}
if(typeof conf=='string'){conf={color:conf};}
var globals=$.extend({},$.tools.expose.conf);conf=$.extend(globals,conf);this.each(function(){el=new Expose($(this),conf);$(this).data("expose",el);});return conf.api?el:this;};})(jQuery);