(function(n,t){function c(){n.removeEventListener("load",c,!1);u=!0}function i(n){return f=f||new i.Class(n)}function s(n,t){for(var i in t)n[i]=t[i];return n}var h="addEventListener"in n,u=!1,l,a,f,e,r,v,o;t.readyState==="complete"?u=!0:h&&n.addEventListener("load",c,!1);l=/\/ath(\/)?$/;a=/([\?&]ath=[^&]*$|&ath=[^&]*(&))/;i.intl={en_us:{ios:"To add us to your home screen: tap %icon and then <strong>Add to Home Screen<\/strong>.",android:'To add us to your home screen open the browser option menu and tap on <strong>Add to homescreen<\/strong>. <small>The menu can be accessed by pressing the menu hardware button if your device has one, or by tapping the top right menu icon <span class="ath-action-icon">icon<\/span>.<\/small>',windows:"To pin us to your Start screen tap <strong>More<\/strong> then tap <strong>Pin to start<\/strong>"}};for(e in i.intl)i.intl[e.substr(0,2)]=i.intl[e];i.defaults={appID:"org.perkspot.addtohome",fontSize:15,debug:!1,modal:!1,mandatory:!1,autostart:!0,skipFirstVisit:!1,startDelay:0,lifespan:0,displayPace:10080,maxDisplayCount:0,icon:!1,message:"",validLocation:[RegExp("(.com|.net|.local)/$")],onInit:null,onShow:null,onRemove:null,onAdd:null,onPrivate:null,privateModeOverride:!1,detectHomescreen:!1};r=n.navigator.userAgent;v=n.navigator;s(i,{hasToken:!1,isRetina:n.devicePixelRatio&&n.devicePixelRatio>1,isIDevice:/iphone|ipod|ipad/i.test(r),isMobileChrome:r.indexOf("Android")>-1&&/Chrome\/[.0-9]*/.test(r),isMobileIE:r.indexOf("Windows Phone")>-1,language:"en_us"});i.isMobileSafari=i.isIDevice&&r.indexOf("Safari")>-1&&r.indexOf("CriOS")<0;i.OS=i.isIDevice?"ios":i.isMobileChrome?"android":i.isMobileIE?"windows":"unsupported";i.OSVersion=r.match(/(OS|Android) (\d+[_\.]\d+)/);i.OSVersion=i.OSVersion&&i.OSVersion[2]?+i.OSVersion[2].replace("_","."):0;i.isStandalone=n.navigator.standalone||i.isMobileChrome&&screen.height-t.documentElement.clientHeight<40;i.isTablet=i.isMobileSafari&&r.indexOf("iPad")>-1||i.isMobileChrome&&r.indexOf("Mobile")<0;i.isCompatible=i.isMobileSafari&&i.OSVersion>=6||i.isMobileChrome||i.IsMobileIE;o={lastDisplayTime:0,returningVisitor:!1,displayCount:0,optedout:!1,added:!1};i.removeSession=function(n){try{localStorage.removeItem(n||i.defaults.appID)}catch(t){}};i.Class=function(n){var r,u;if((this.options=s({},i.defaults),s(this.options,n),h)&&(this.options.mandatory=!1,this.options.modal=!1,this.options.detectHomescreen=this.options.detectHomescreen===!0?"hash":this.options.detectHomescreen,this.options.debug&&(i.isCompatible=!0,i.OS=typeof this.options.debug=="string"?this.options.debug:i.OS=="unsupported"?"android":i.OS,i.OSVersion=i.OS=="ios"?"8":"4"),this.container=t.documentElement,this.session=localStorage.getItem(this.options.appID),this.session=this.session?JSON.parse(this.session):undefined,i.isCompatible)){this.session=this.session||o;try{localStorage.setItem(this.options.appID,JSON.stringify(this.session));i.hasLocalStorage=!0}catch(f){i.hasLocalStorage=!1;this.options.onPrivate&&this.options.onPrivate.call(this)}for(r=!this.options.validLocation.length,u=this.options.validLocation.length;u--;)if(this.options.validLocation[u].test(t.location.href)){r=!0;break}if(!this.session.optedout&&!this.session.added&&r){if(i.isStandalone){this.session.added||(this.session.added=!0,this.updateSession(),this.options.onAdd&&i.hasLocalStorage&&this.options.onAdd.call(this));return}(this.session.returningVisitor||(this.session.returningVisitor=!0,this.updateSession(),!this.options.skipFirstVisit))&&(this.options.privateModeOverride||i.hasLocalStorage)&&(this.ready=!0,this.options.onInit&&this.options.onInit.call(this),this.options.autostart&&this.show())}}};i.Class.prototype={events:{load:"_delayedShow",error:"_delayedShow",orientationchange:"resize",resize:"resize",scroll:"resize",click:"forceRemove",touchmove:"_preventDefault",transitionend:"_removeElements",webkitTransitionEnd:"_removeElements",MSTransitionEnd:"_removeElements"},handleEvent:function(n){var t=this.events[n.type];t&&this[t](n)},show:function(n){var f,e,r;if(this.options.autostart&&!u){setTimeout(this.show.bind(this),50);return}if(!this.shown){if(f=Date.now(),e=this.session.lastDisplayTime,n!==!0){if(!this.ready)return;if(f-e<this.options.displayPace*6e4)return;if(this.options.maxDisplayCount&&this.session.displayCount>=this.options.maxDisplayCount)return}this.shown=!0;this.session.lastDisplayTime=f;this.session.displayCount++;this.updateSession();this.applicationIcon||(this.applicationIcon=i.OS=="ios"?t.querySelector('head link[rel^=apple-touch-icon][sizes="152x152"],head link[rel^=apple-touch-icon][sizes="144x144"],head link[rel^=apple-touch-icon][sizes="120x120"],head link[rel^=apple-touch-icon][sizes="114x114"],head link[rel^=apple-touch-icon]'):t.querySelector('head link[rel^="shortcut icon"][sizes="196x196"],head link[rel^=apple-touch-icon]'));r=i.intl[i.language][i.OS];r="<p>"+r.replace("%icon",'<span class="ath-action-icon">icon<\/span>')+"<\/p>";this.viewport=t.createElement("div");this.viewport.className="ath-viewport";this.options.modal&&(this.viewport.className+=" ath-modal");this.options.mandatory&&(this.viewport.className+=" ath-mandatory");this.viewport.style.position="relative";this.element=t.createElement("div");this.element.className="ath-container ath-"+i.OS+" ath-"+i.OS+(i.OSVersion+"").substr(0,1)+" ath-"+(i.isTablet?"tablet":"phone");this.element.style.cssText="-webkit-transition-property:-webkit-transform,opacity;-webkit-transition-duration:0s;-webkit-transition-timing-function:ease-out;transition-property:transform,opacity;transition-duration:0s;transition-timing-function:ease-out;";this.element.style.opacity="0";this.element.style.maxHeight="0";this.options.icon&&this.applicationIcon&&(this.element.className+=" ath-icon",this.img=t.createElement("img"),this.img.className="ath-application-icon",this.img.addEventListener("load",this,!1),this.img.addEventListener("error",this,!1),this.img.src=this.applicationIcon.href,this.element.appendChild(this.img));this.element.innerHTML+=r;this.viewport.style.left="-99999em";this.viewport.appendChild(this.element);t.body.insertBefore(this.viewport,t.getElementById("mainPage"));this.img||this._delayedShow()}},_delayedShow:function(){setTimeout(this._show.bind(this),this.options.startDelay*1e3+500)},_show:function(){var i=this;this.updateViewport();n.addEventListener("resize",this,!1);n.addEventListener("scroll",this,!1);n.addEventListener("orientationchange",this,!1);this.options.modal&&t.addEventListener("touchmove",this,!0);this.options.mandatory||setTimeout(function(){i.element.addEventListener("click",i,!0)},1e3);setTimeout(function(){i.element.style.opacity="1";i.element.style.maxHeight="500px";i.element.style.transitionDuration="300ms"},0);this.options.lifespan&&(this.removeTimer=setTimeout(this.remove.bind(this),this.options.lifespan*1e3));this.options.onShow&&this.options.onShow.call(this)},forceRemove:function(){this.remove();this.optOut()},remove:function(){clearTimeout(this.removeTimer);this.img&&(this.img.removeEventListener("load",this,!1),this.img.removeEventListener("error",this,!1));n.removeEventListener("resize",this,!1);n.removeEventListener("scroll",this,!1);n.removeEventListener("orientationchange",this,!1);t.removeEventListener("touchmove",this,!0);this.element.removeEventListener("click",this,!0);this.element.addEventListener("transitionend",this,!1);this.element.addEventListener("webkitTransitionEnd",this,!1);this.element.addEventListener("MSTransitionEnd",this,!1);this.element.style.webkitTransitionDuration="0.3s";this.element.style.opacity="0"},_removeElements:function(){this.element.removeEventListener("transitionend",this,!1);this.element.removeEventListener("webkitTransitionEnd",this,!1);this.element.removeEventListener("MSTransitionEnd",this,!1);t.body.removeChild(this.viewport);this.shown=!1;this.options.onRemove&&this.options.onRemove.call(this)},updateViewport:function(){var r,u;this.shown&&(this.viewport.style.width="100%",this.viewport.style.height="auto",this.viewport.style.left="0",this.viewport.style.top="0",r=t.documentElement.clientWidth,this.orientation=r>t.documentElement.clientHeight?"landscape":"portrait",u=i.OS=="ios"?this.orientation=="portrait"?screen.width:screen.height:screen.width,this.scale=screen.width>r?1:u/n.innerWidth,this.element.style.fontSize=this.options.fontSize/this.scale+"px")},resize:function(){clearTimeout(this.resizeTimer);this.resizeTimer=setTimeout(this.updateViewport.bind(this),100)},updateSession:function(){i.hasLocalStorage!==!1&&localStorage.setItem(this.options.appID,JSON.stringify(this.session))},clearSession:function(){this.session=o;this.updateSession()},optOut:function(){this.session.optedout=!0;this.updateSession()},optIn:function(){this.session.optedout=!1;this.updateSession()},clearDisplayCount:function(){this.session.displayCount=0;this.updateSession()},_preventDefault:function(n){n.preventDefault();n.stopPropagation()}};n.addToHomescreen=i})(window,document)