(function(root,factory){if(typeof define==="function"&&define.amd){define(function(){return factory(root,document,{});});}
else if(typeof exports!=="undefined"){if(global&&global.testEnv){factory(global.testEnv,global.testEnv.document,exports);}
else{factory(root,document,exports);}}
else{root.Bounceback=factory(root,document,{});}})(window,function(root,doc,Bounceback){var addEvent=function(elm,evt,cb){if(elm.attachEvent){elm.attachEvent("on"+evt,cb);}
else{elm.addEventListener(evt,cb,false);}};var oldBounceback=root.Bounceback;Bounceback.noConflict=function(){root.Bounceback=oldBounceback;return this;};Bounceback.version="1.0.0";Bounceback.options={distance:100,maxDisplay:1,method:"auto",sensitivity:10,cookieLife:365,scrollDelay:500,aggressive:false,checkReferrer:true,storeName:"bounceback-visited",onBounce:function(){return Bounceback;}};Bounceback.data={get:function(key){if(root.localStorage){return root.localStorage.getItem(key)||"";}
else{var cookies=doc.cookie.split(";");var i=-1,data=[],cVal="",cName="",length=cookies.length;while(++i<length){data=cookies[i].split("=");if(data[0]==key){data.shift();return data.join("=");}}
return "";}},set:function(key,value){if(root.localStorage){root.localStorage.setItem(key,value);}
else{var dt=new Date();dt.setDate(dt.getDate()+Bounceback.options.cookieLife);doc.cookie=key+"="+value+"; expires="+dt.toUTCString()+";path=/;";}
return this;}};var shown=0;Bounceback.onBounce=function(){shown++;if(!this.options.maxDisplay||shown<=this.options.maxDisplay){this.options.onBounce();}};Bounceback.isMobile=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(root.navigator.userAgent);Bounceback.disabled=false;Bounceback.activated=false;Bounceback.disable=function(){this.disabled=true;return this;};Bounceback.enable=function(){this.disabled=false;return this;};Bounceback.activate=function(method){if(method=="history"){if("replaceState"in root.history){root.history.replaceState({isBouncing:true},root.title);root.history.pushState(null,root.title);addEvent(root,"popstate",function(e){if(root.history.state&&root.history.state.isBouncing){Bounceback.onBounce();}});}
else if("onhashchange"in root){root.location.replace("#bht");root.location.hash="";addEvent(root,"hashchange",function(){if(root.location.hash.substr(-3)==="bht"){Bounceback.onBounce();}});}}
else{var timer=null,movements=[],scrolling=false;addEvent(doc,"mousemove",function(e){movements.unshift({x:e.clientX,y:e.clientY});movements=movements.slice(0,10);});addEvent(doc,"mouseout",function(e){if(!Bounceback.disabled){var from=e.relatedTarget||e.toElement;if((!from||from.nodeName=="HTML")&&e.clientY<=Bounceback.options.distance&&movements.length==10&&movements[0].y<movements[9].y&&movements[9].y-movements[0].y>Bounceback.options.sensitivity){Bounceback.onBounce();}}});if(this.options.scrollDelay){addEvent(root,"scroll",function(e){if(!Bounceback.disabled){Bounceback.disabled=true;clearTimeout(timer);timer=setTimeout(function(){Bounceback.disabled=false;},Bounceback.options.scrollDelay);}});}}};Bounceback.init=function(options){options=options||{};var key;for(key in this.options){if(this.options.hasOwnProperty(key)&&!options.hasOwnProperty(key)){options[key]=this.options[key];}}
this.options=options;if(options.checkReferrer&&doc.referrer){var a=doc.createElement("a");a.href=doc.referrer;if(a.host==root.location.host){this.data.set(options.storeName,"1");}}
if(!this.activated&&(options.aggressive||!this.data.get(options.storeName))){this.activated=true;if(options.method==="history"||(options.method==="auto"&&this.isMobile)){this.activate("history");}
else{this.activate("mouse");}
this.data.set(options.storeName,"1");}
return this;};return Bounceback;});