/*
 * Use Break Activity Message Module
 * Version: 1.2
 * Author: tdeater@biggs-gilmore.com
 *
 * Requires: UBAMConfig object (see http://library.kelloggs.com/ubam/ubam_config_us_en_redirect.js.asp)
 */

if(typeof UBAM=="undefined"){var UBAM=(function(){var d,j={},u={},l=0,g=0,C=0,U=document.getElementsByTagName("body")[0];var Q,X,a,p,F,i,S,P,t,f;var o,M,r,Z,A,G;var V={sitename:location.hostname,timerwidth:600,trackingurl:"/ubam/tracking.html",debug:false};var q=(function(){var w,AA,AC,AD,AB,x,z={};w=window.location.toString();AA=w.indexOf("?");if(AA==-1){return z;}AC=w.substring(AA+1,w.length);AD=AC.split("&");for(var y=0;y<AD.length;y++){AB=AD[y].split("=");if(AB[1]){x=AB[1].split("#");z[AB[0].toLowerCase()]=x[0];}}return z;})();var Y=function(x,AF,AI){if(typeof AF!="undefined"){AI=AI||{};if(AF===null){AF="";AI.expires=-1;}var AA="";if(AI.expires&&(typeof AI.expires=="number"||AI.expires.toUTCString)){var AB;if(typeof AI.expires=="number"){AB=new Date();AB.setTime(AB.getTime()+(AI.expires*24*60*60*1000));}else{AB=AI.expires;}AA="; expires="+AB.toUTCString();}var AH=AI.path?"; path="+AI.path:"";var AD=AI.domain?"; domain="+AI.domain:"";var w=AI.secure?"; secure":"";document.cookie=[x,"=",encodeURIComponent(AF),AA,AH,AD,w].join("");}else{var z=null;if(document.cookie&&document.cookie!==""){var AG=document.cookie.split(";");for(var AE=0,AC=AG.length;AE<AC;AE++){var y=AG[AE].replace(/^\s+|\s+$/g,"");if(y.substring(0,x.length+1)==(x+"=")){z=decodeURIComponent(y.substring(x.length+1));break;}}}return z;}};var O=function(){var z=arguments[0]||{},w,y=arguments.length,AA;for(w=1;w<y;w++){if((AA=arguments[w])!==null){for(var x in AA){if(z==AA[x]){continue;}else{if(AA[x]!==undefined){z[x]=AA[x];}}}}}return z;};var J=function(){if(V.debug||window.location.hash.match(/debug/i)){try{if(typeof loadFirebugConsole==="function"&&typeof console==="undefined"){window.loadFirebugConsole();}console.log.apply(this,arguments);}catch(x){var w="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js";J.arg.push(arguments);if(!c[w]){c(w,function(){try{var y;firebug.init();while(y=J.arg.shift()){J(y);}}catch(z){}});}}}};J.arg=[];var T=function(){var w=Math.max(document.documentElement.scrollWidth||document.body.scrollWidth,document.body.offsetWidth);var z=Math.max(document.documentElement.scrollHeight||document.body.scrollHeight,document.body.offsetHeight);return{"x":w,"y":z};};var v=function(){var w=self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;var z=self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;return{"x":w,"y":z};};var m=function(){var w=self.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft;var z=self.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop;return{"x":w,"y":z};};var I=function(w){return document.getElementById(w);};var n=function(AA,AB,z,y){var w=z||document.getElementsByTagName("body")[0];var x=document.createElement(AA);x.id=AB;if(y){w.insertBefore(x,y);}else{w.appendChild(x);}return x;};var B=function(w,x){if(w&&x){var y;for(y in x){if(x.hasOwnProperty(y)){w.style[y]=x[y];}}}};var h=function(x,w){if(typeof x=="string"){x=I(x);}if(x.currentStyle){return x.currentStyle[w];}else{if(window.getComputedStyle){return document.defaultView.getComputedStyle(x,null).getPropertyValue(w);}}};var k=function(w){if(typeof w=="string"){w=I(w);}w.style.display=(w.style.display=="none")?"block":"none";};var e=function(w){if(typeof w=="string"){w=I(w);}w.style.visibility=(w.style.visibility=="hidden")?"visible":"hidden";};var L=function(){if(C==100){clearInterval(P);P=null;return ;}var x=document.getElementsByTagName("object");if(x.length!=l){l=x.length;[].forEach.call(x,function(z,y,AA){if(!j[z.id]){j[z.id]={};j[z.id].height=h(z,"height");j[z.id].minheight=h(z,"minHeight");}z.style.height=0;z.style.minHeight=0;});}var w=document.getElementsByTagName("embed");if(w.length!=g){g=w.length;[].forEach.call(w,function(z,y,AA){if(!u[z.id]){u[z.id]={};u[z.id].height=h(z,"height");u[z.id].minheight=h(z,"min-height");}z.style.height=0;z.style.minHeight=0;});}C++;};var b=function(){var x=document.getElementsByTagName("object");[].forEach.call(x,function(z,y,AA){z.style.height=j[z.id].height;z.style.minHeight=j[z.id].minheight;});var w=document.getElementsByTagName("embed");[].forEach.call(w,function(z,y,AA){z.style.height=u[z.id].height;z.style.minHeight=u[z.id].minheight;});l=0;g=0;C=0;};var E=function(){if(document.all){[].forEach.call(document.getElementsByTagName("select"),function(x,w,y){e(x);});}};var D=function(){var y=T(),w=v(),x=m();y.x=Math.max(y.x,w.x);y.y=Math.max(y.y,w.y);if((o=I("ubam-overlay"))){B(o,{width:y.x+"px",height:y.y+"px"});}if((M=I("ubam-messagebox"))){B(M,{top:Math.round(w.y/2+x.y-UBAMConfig.ycenteroffset)+"px",left:(w.x/2+x.x)+"px"});}};var H=function(){var x,w="",y=Math.max(F,0);B(Z,{width:Math.round(y/UBAMConfig.timerwhen*(V.timerwidth-UBAMConfig.counterwidth))+"px"});if(UBAMConfig.timerwhen>59){w=Math.max(Math.floor(y/60),0).toString();w=(w.length<2)?"0"+w:w;y=y%60;}y=y.toString();y=(y.length<2)?"0"+y:y;x=UBAMConfig.timercounterhtml.replace(/%s/,y);x=x.replace(/%m/,w);A.innerHTML=x;if(r.style.display=="none"){B(r,{display:"block"});}};var N=function(){B(r,{display:"none"});};var K=function(y,w,x){if(typeof y=="string"){y=I(y);}var z=y[w];if(typeof z=="function"){y[w]=function(){z();x();};}else{y[w]=x;}};var s=function(){Y("ublength",i,{path:"/"});Y("ubstart",Q,{path:"/"});Y("ubend",X,{path:"/"});Y("ubcounter",a,{path:"/"});};var c=function(y,AA){if(!c[y]){c[y]="loading";var w=false,z=document.getElementsByTagName("head")[0],x=document.createElement("script");x.setAttribute("type","text/javascript");x.setAttribute("src",y);x.onload=x.onreadystatechange=x.onerror=function(){J(y,"readystate",this.readyState);if(!w&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){w=true;c[y]="complete";if(typeof AA==="function"){AA();}x.onload=x.onreadystatechange=x.onerror=null;z.removeChild(x);}};z.appendChild(x);}};var R=function(AA,AB){try{var w=(("https:"==document.location.protocol)?"https://ssl.":"http://www.")+"google-analytics.com/ga.js";if(AA){R.trackers.push({str:AA,callback:AB});J(R.trackers);}if(typeof _gat==="undefined"&&!R.abort){switch(c[w]){case"complete":R.abort=true;break;case"loading":J("waiting for GA script",AA);return ;break;default:J("loading GA script",AA);c(w,R);return ;}}var x,z;while(x=R.trackers.shift()){if(!R.abort){J("trackPageview",x.str);z=z||_gat._getTracker("UA-2860895-24");z._trackPageview(x.str);}else{J("tracking aborted",x.str);}if(typeof x.callback==="function"){x.callback();}}}catch(y){J(y,c[w]);if(typeof AB==="function"){AB();}}};R.abort=false;R.trackers=[];var W=function(){f=5000;i=(parseInt(q.seconds,10)||Y("ublength")||V.seconds||UBAMConfig.maxseconds)*1;i=Math.min(i,UBAMConfig.maxseconds);p=(new Date()).getTime();Q=(Y("ubstart")||(new Date()).getTime())*1;X=(Y("ubend")||(Q+(i*1000)))*1;a=(Y("ubcounter")||0)*1;Y("ublength",i,{path:"/"});Y("ubstart",Q,{path:"/"});Y("ubend",X,{path:"/"});J("start/end/length",Q,X,i);if(a==-1){d.trigger();return ;}if((r=I("ubam-timer"))&&!(I("ubam-timer-bg"))){var y,w;N();y=n("div","ubam-timer-bg",r);Z=n("div","ubam-timer-bar",y);w=n("div","ubam-timer-label",y);w.innerHTML=UBAMConfig.timerlblhtml;A=n("div","ubam-timer-counter",y);UBAMConfig.timerbgstyle=O(UBAMConfig.timerbgstyle,{width:V.timerwidth+"px"});B(y,UBAMConfig.timerbgstyle);UBAMConfig.timerbarstyle=O(UBAMConfig.timerbarstyle,{width:(V.timerwidth-UBAMConfig.counterwidth)+"px"});B(Z,UBAMConfig.timerbarstyle);UBAMConfig.timerlblstyle=O(UBAMConfig.timerlblstyle,{width:(V.timerwidth-UBAMConfig.counterwidth)+"px"});B(w,UBAMConfig.timerlblstyle);B(A,UBAMConfig.timercounterstyle);}var x=function(){p=(new Date()).getTime();var z=Q+a-p;if(z>60000){X-=z;Q-=z;Y("ubstart",Q,{path:"/"});Y("ubend",X,{path:"/"});}else{a-=z;}F=d.getCountdown();J("drift/counter/interval/mod/remaining",z,a,t,p%f,F);if(F<=0){d.trigger();return ;}if(F<=UBAMConfig.timerwhen){f=1000;if(r){H();}}t=f-(p%f);a+=t;Y("ubcounter",a,{path:"/"});S=setTimeout(x,t);};F=d.getCountdown();if(F<=UBAMConfig.timerwhen){f=1000;if(r){H();}}t=f-(p%f);a+=t;Y("ubcounter",a,{path:"/"});setTimeout(x,t);};return{init:function(w){V=O(V,w);V.timerwidth=V.timerwidth-V.timerwidth%2;K(window,"onresize",D);K(window,"onscroll",function(){setTimeout(D,200);});K(window,"onunload",s);if(V.debug&&q.clear=="1"){Y("ubcounter",null,{path:"/"});Y("ublength",null,{path:"/"});Y("ubstart",null,{path:"/"});Y("ubend",null,{path:"/"});}d=this;W();},trigger:function(){var x,y,AB,AA=T(),w=v(),z=m();AA.x=Math.max(AA.x,w.x);AA.y=Math.max(AA.y,w.y);clearTimeout(S);S=null;a=-1;Y("ubcounter",a,{path:"/"});if(!(o=I("ubam-overlay"))){o=n("div","ubam-overlay");UBAMConfig.overlaystyle=O(UBAMConfig.overlaystyle,{width:AA.x+"px",height:AA.y+"px"});B(o,UBAMConfig.overlaystyle);}if(!(M=I("ubam-messagebox"))){M=n("div","ubam-messagebox");UBAMConfig.msgboxstyle=O(UBAMConfig.msgboxstyle,{top:Math.round(w.y/2+z.y-UBAMConfig.ycenteroffset)+"px",left:(w.x/2+z.x)+"px"});B(M,UBAMConfig.msgboxstyle);x=n("div","ubam-logo",M);B(x,UBAMConfig.logostyle);x.innerHTML='<img src="'+V.logo+'" onerror="this.style.display=\'none\'" />';y=n("div","ubam-message",M);B(y,UBAMConfig.msgstyle);y.innerHTML=UBAMConfig.msghtml;AB=n("div","ubam-footer",M);B(AB,UBAMConfig.footerstyle);AB.innerHTML=UBAMConfig.footerhtml;}L();P=setInterval(L,200);E();N();G=h(U,"width");B(U,{width:"auto"});k(o);k(M);J("accuracy (now - ubend)",(new Date().getTime())-X);R("/"+V.sitename+"/View");},dismiss:function(){R("/"+V.sitename+"/Continue",function(){clearInterval(P);P=null;k(M);k(o);B(U,{width:G});b();E();Y("ubcounter",null,{path:"/"});Y("ublength",null,{path:"/"});Y("ubstart",null,{path:"/"});Y("ubend",null,{path:"/"});W();});},redirect:function(){R("/"+V.sitename+"/Redirect",function(){location.href=UBAMConfig.redirecturl;});},quit:function(){R("/"+V.sitename+"/Quit",function(){window.open("about:blank","_parent","");window.opener=self;window.close();});},getCountdown:function(){return Math.round((X-p)/1000);},getCountdownPercent:function(){return Math.round(this.getCountdown()/i*100);}};})();}if(!Array.prototype.forEach){Array.prototype.forEach=function(C,D){var A=this.length;for(var B=0;B<A;B++){C.call(D,this[B],B,this);}};}
