(function(g,j,n,e){g.fn.sonar=function(q,p){if(typeof q==="boolean"){p=q;q=e}return g.sonar(this[0],q,p)};var h=n.body,c=g(j),b="scrollin",o="scrollout",a=function(t,p,v){if(t){h||(h=n.body);var u=t,w=0,x=h.offsetHeight,q=j.innerHeight||n.documentElement.clientHeight||h.clientHeight||0,s=n.documentElement.scrollTop||j.pageYOffset||h.scrollTop||0,r=t.offsetHeight||0;if(!t.sonarElemTop||t.sonarBodyHeight!==x){if(u.offsetParent){do{w+=u.offsetTop}while(u=u.offsetParent)}t.sonarElemTop=w;t.sonarBodyHeight=x}p=p===e?0:p;return(!(t.sonarElemTop+(v?0:r)<s-p)&&!(t.sonarElemTop+(v?r:0)>s+q+p))}},f={},l=0,d,k=function(){d&&clearTimeout(d);d=setTimeout(function(){var u,q,v,s,r,t,p;for(v in f){q=f[v];for(t=0,p=q.length;t<p;t++){s=q[t];u=s.elem;r=a(u,s.px,s.full);if(v===o?!r:r){if(!s.tr){if(u[v]){g(u).trigger(v);s.tr=1}else{q.splice(t,1);t--;p--}}}else{s.tr=0}}}},0)},m=function(p,q){p[q]=0},i=function(u,r){var w=r.px,s=r.full,v=r.evt,t=j,q=a(u,w,s),p=0;u[v]=1;if(v===o?!q:q){setTimeout(function(){g(u).trigger(v===o?o:b)},0);p=1}f[v].push({elem:u,px:w,full:s,tr:p});if(!l){c.bind("scroll",k);l=1}};g.sonar=a;f[b]=[];g.event.special[b]={add:function(p){var r=p.data||{},q=this;if(!q[b]){i(this,{px:r.distance,full:r.full,evt:b})}},remove:function(p){m(this,b)}};f[o]=[];g.event.special[o]={add:function(p){var r=p.data||{},q=this;if(!q[o]){i(q,{px:r.distance,full:r.full,evt:o})}},remove:function(p){m(this,o)}}})(jQuery,window,document);
