/*
 * Kellogg Ipsos Module
 * Version: 1.0
 * Author: tdeater@biggs-gilmore.com
 *
 *
 
The Ipsos module is initialized in the <head> of each page, *before* the HAM module is initialized:

IPSOS.init({
	overlaystyle: {background: "#582d85 url(/ipsos_test/overlay.jpg) 50% 50% no-repeat"}, // required, object: CSS rules for the overlay element
	yesbutton: {path: "/ipsos_test/button_yes.jpg", left: 110, top: 305}, // required, object: path and X/Y coordinates for positioning of YES button image
	nobutton: {path: "/ipsos_test/button_no.jpg", left: 300, top: 305}, // required, object: path and X/Y coordinates for positioning of NO button image
	message: "/ipsos_test/message.jpg", // required, string: path of the Ipsos prompt message image
	surveyurl: "http://surveys.globalepanel.com/wix/p214491826.aspx", // required, string: URL of the Ipsos survey
	promptagain: 12, // optional, number: how many weeks to wait before prompting the user to take a survey again after they have taken it (default value: 12)
	debug: true, // optional, boolean: enable special debugging mode (for testing only, NOT FOR PRODUCTION USE!)
	minutes: 0.2 // optional, number: display Ipsos prompt after specified # of minutes (for testing only, NOT FOR PRODUCTION USE!)
});

 */
 
if(typeof IPSOS=="undefined"){var IPSOS=(function(){var e,k={},z={},m=0,h=0,B=0,S=null;var W,Z,Y,v,F,o,b,P,x,g=5000;var s,M,G;var a,R,j=location.hostname;var r=navigator.userAgent.toLowerCase(),N=/msie/.test(r)&&!/opera/.test(r);var H=10,d=H*60;var p={position:"absolute",top:"0",left:"0",zIndex:"9998",display:"none"},D={position:"absolute",zIndex:"9999",marginLeft:Math.round(0-600/2)+"px",marginTop:Math.round(0-400/2)+"px",display:"none"};var T={promptagain:12,debug:false};var u=function(){var AB=document.getElementsByTagName("body")[0];if(!AB){return false;}u=function(){return true;};};var V=function(){if(u()){S=document.getElementsByTagName("body")[0];}else{window.setTimeout(V,250);}};var y=function(AB,AD){var AC=true;Array.prototype.forEach.call(AB,function(AF,AE,AG){if(!AF.complete){AC=false;}});if(AC&&typeof AD==="function"){AD();}else{window.setTimeout(function(){y(AB,AD);},250);}};var t=(function(){var AB,AF,AH,AI,AG,AC,AE={};AB=window.location.toString();AF=AB.indexOf("?");if(AF==-1){return AE;}AH=AB.substring(AF+1,AB.length);AI=AH.split("&");for(var AD=0;AD<AI.length;AD++){AG=AI[AD].split("=");if(AG[1]){AC=AG[1].split("#");AE[AG[0].toLowerCase()]=AC[0];}}return AE;})();var X=function(AC,AK,AN){if(typeof AK!="undefined"){AN=AN||{};if(AK===null){AK="";AN.expires=-1;}var AF="";if(AN.expires&&(typeof AN.expires=="number"||AN.expires.toUTCString)){var AG;if(typeof AN.expires=="number"){AG=new Date();AG.setTime(AG.getTime()+(AN.expires*24*60*60*1000));}else{AG=AN.expires;}AF="; expires="+AG.toUTCString();}var AM=AN.path?"; path="+AN.path:"";var AI=AN.domain?"; domain="+AN.domain:"";var AB=AN.secure?"; secure":"";document.cookie=[AC,"=",encodeURIComponent(AK),AF,AM,AI,AB].join("");}else{var AE=null;if(document.cookie&&document.cookie!==""){var AL=document.cookie.split(";");for(var AJ=0,AH=AL.length;AJ<AH;AJ++){var AD=AL[AJ].replace(/^\s+|\s+$/g,"");if(AD.substring(0,AC.length+1)==(AC+"=")){AE=decodeURIComponent(AD.substring(AC.length+1));break;}}}return AE;}};var O=function(){var AE=arguments[0]||{},AB,AD=arguments.length,AF;for(AB=1;AB<AD;AB++){if((AF=arguments[AB])!==null){for(var AC in AF){if(AE==AF[AC]){continue;}else{if(AF[AC]!==undefined){AE[AC]=AF[AC];}}}}}return AE;};var J=function(){if(T.debug){try{if(typeof loadFirebugConsole==="function"&&typeof console==="undefined"){window.loadFirebugConsole();}console.log(arguments);}catch(AB){}}};var Q=function(){var AB=Math.max(document.documentElement.scrollWidth||document.body.scrollWidth,document.body.offsetWidth);var AC=Math.max(document.documentElement.scrollHeight||document.body.scrollHeight,document.body.offsetHeight);return{"x":AB,"y":AC};};var AA=function(){var AB=self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;var AC=self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;return{"x":AB,"y":AC};};var n=function(){var AB=self.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft;var AC=self.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop;return{"x":AB,"y":AC};};var I=function(AB){return document.getElementById(AB);};var q=function(AF,AG,AE,AD){var AB=AE||document.getElementsByTagName("body")[0];var AC=document.createElement(AF);AC.id=AG;if(AD){AB.insertBefore(AC,AD);}else{AB.appendChild(AC);}return AC;};var A=function(AB,AC){if(AB&&AC){var AD;for(AD in AC){if(AC.hasOwnProperty(AD)){if(AD==="opacity"&&N){AB.style.zoom=1;AB.style.filter=(AB.style.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(AC[AD])+""=="NaN"?"":"alpha(opacity="+AC[AD]*100+")");}else{AB.style[AD]=AC[AD];}}}}};var i=function(AC,AB){if(typeof AC=="string"){AC=I(AC);}if(AC.currentStyle){return AC.currentStyle[AB];}else{if(window.getComputedStyle){return document.defaultView.getComputedStyle(AC,null).getPropertyValue(AB);}}};var l=function(AB){if(typeof AB=="string"){AB=I(AB);}AB.style.display=(AB.style.display=="none")?"block":"none";};var f=function(AB){if(typeof AB=="string"){AB=I(AB);}AB.style.visibility=(AB.style.visibility=="hidden")?"visible":"hidden";};var L=function(){if(B==100){window.clearInterval(P);P=null;return ;}var AC=document.getElementsByTagName("object"),AD=null;if(AC.length!=m){m=AC.length;Array.prototype.forEach.call(AC,function(AF,AE,AG){if(!k[AF.id]){k[AF.id]={};k[AF.id].height=i(AF,"height");k[AF.id].minheight=i(AF,"minHeight");AD=AF.getElementsByTagName("param");Array.prototype.forEach.call(AD,function(AJ,AI,AH){if(AJ.parentNode===AF&&AJ.name.match(/^wmode$/i)&&AJ.value.match(/^(transparent)|(opaque)$/i)){k[AF.id].wmode=true;}});}if(!k[AF.id].wmode){AF.style.height=0;AF.style.minHeight=0;}});}var AB=document.getElementsByTagName("embed");if(AB.length!=h){h=AB.length;Array.prototype.forEach.call(AB,function(AF,AE,AG){if(!z[AF.id]){z[AF.id]={};z[AF.id].height=i(AF,"height");z[AF.id].minheight=i(AF,"min-height");if(AF.getAttribute("wmode")&&AF.getAttribute("wmode").match(/^(transparent)|(opaque)$/i)){z[AF.id].wmode=true;}}if(!z[AF.id].wmode){AF.style.height=0;AF.style.minHeight=0;}});}B++;};var c=function(){var AC=document.getElementsByTagName("object");Array.prototype.forEach.call(AC,function(AE,AD,AF){if(!k[AE.id].wmode){AE.style.height=k[AE.id].height;AE.style.minHeight=k[AE.id].minheight;}});var AB=document.getElementsByTagName("embed");Array.prototype.forEach.call(AB,function(AE,AD,AF){if(!z[AE.id].wmode){AE.style.height=z[AE.id].height;AE.style.minHeight=z[AE.id].minheight;}});m=0;h=0;B=0;};var E=function(){if(document.all){Array.prototype.forEach.call(document.getElementsByTagName("select"),function(AC,AB,AD){f(AC);});}};var C=function(){var AD=Q(),AB=AA(),AC=n();AD.x=Math.max(AD.x,AB.x);AD.y=Math.max(AD.y,AB.y);if((s=I("ipsos-overlay"))){A(s,{width:AD.x+"px",height:AD.y+"px",backgroundPosition:"50% "+AC.y+"px"});}if((M=I("ipsos-messagebox"))){A(M,{top:Math.round(AB.y/2+AC.y-20)+"px",left:(AB.x/2+AC.x)+"px"});}};var K=function(AD,AB,AC){if(typeof AD=="string"){AD=I(AD);}var AE=AD[AB];if(typeof AE=="function"){AD[AB]=function(){AE();AC();};}else{AD[AB]=AC;}};var w=function(){X("iplength",o,{path:"/"});X("ipstart",W,{path:"/"});X("ipend",Z,{path:"/"});X("ipcounter",Y,{path:"/"});};var U=function(){o=(parseInt(t.minutes,10)*60||X("iplength")||T.minutes*60||Math.floor(Math.random()*(H+1))*60)*1;o=Math.min(o,d);if(X("ipreferrer")==="don't know"&&!T.debug){o=Math.max(o,60);}v=(new Date()).getTime();W=(X("ipstart")||(new Date()).getTime())*1;Z=(X("ipend")||(W+(o*1000)))*1;Y=(X("ipcounter")||0)*1;X("iplength",o,{path:"/"});X("ipstart",W,{path:"/"});X("ipend",Z,{path:"/"});J("start/end/length (seconds)",W,Z,o);if(Y==-1){e.trigger();return ;}var AB=function(){v=(new Date()).getTime();var AC=W+Y-v;if(AC>60000){Z-=AC;W-=AC;X("ipstart",W,{path:"/"});X("ipend",Z,{path:"/"});}else{Y-=AC;}F=e.getCountdown();J("drift/counter/interval/mod/remaining (seconds)",AC,Y,x,v%g,F);if(F<=0){e.trigger();return ;}x=g-(v%g);Y+=x;X("ipcounter",Y,{path:"/"});b=window.setTimeout(AB,x);};F=e.getCountdown();x=g-(v%g);Y+=x;X("ipcounter",Y,{path:"/"});window.setTimeout(AB,x);};return{init:function(AC){T=O(T,AC);if(T.debug&&t.clear=="1"){X("ipcounter",null,{path:"/"});X("iplength",null,{path:"/"});X("ipstart",null,{path:"/"});X("ipend",null,{path:"/"});X("ipsos-prompted",null,{path:"/"});X("ipreferrer",null,{path:"/"});}if(X("ipsos-prompted")){return false;}V();var AB=X("ipreferrer");if(!AB){R=(X("ipsos-visits")||0)*1+1;X("ipsos-visits",R,{path:"/",expires:365});}J("# of visits",X("ipsos-visits"));a=AB||document.referrer||"don't know";X("ipreferrer",a,{path:"/"});K(window,"onresize",C);K(window,"onscroll",function(){window.setTimeout(C,200);});K(window,"onunload",w);e=this;U();},trigger:function(){if(!S){window.setTimeout(e.trigger,250);return false;}var AE,AB,AG=Q(),AD=AA(),AF=n();AG.x=Math.max(AG.x,AD.x);AG.y=Math.max(AG.y,AD.y);window.clearTimeout(b);b=null;Y=-1;X("ipcounter",Y,{path:"/"});if(!(s=I("ipsos-overlay"))){s=q("div","ipsos-overlay");p=O(p,T.overlaystyle);p=O(p,{width:AG.x+"px",height:AG.y+"px",backgroundPosition:"50% "+AF.y+"px"});A(s,p);}if(!(M=I("ipsos-messagebox"))){M=q("div","ipsos-messagebox");D=O(D,{top:Math.round(AD.y/2+AF.y-20)+"px",left:(AD.x/2+AF.x)+"px"});A(M,D);AB=T.surveyurl+"?website="+escape(j)+"&amp;referral="+escape(X("ipreferrer"))+"&amp;visitortype="+escape(X("ipsos-visits"))+"&amp;duration="+escape(o/60);J(AB);AE=q("div","ipsos-message",M);msghtml='<img src="'+T.message+'" alt="">'+'<a href="'+AB+'" target="_blank" '+"onclick=\"window.open(this.href, 'ipsos', 'width=800,height=600,scrollbars,resizable,location').focus();IPSOS.dismiss(true);return false;\">"+'<img src="'+T.yesbutton.path+'" alt="" border="0" id="ipsos-yes"></a>'+'<a href="#" target="_blank" onclick="IPSOS.dismiss(false);return false;">'+'<img src="'+T.nobutton.path+'" alt="" border="0" id="ipsos-no"></a>';AE.innerHTML=msghtml;A(I("ipsos-yes"),{position:"absolute",left:T.yesbutton.left+"px",top:T.yesbutton.top+"px"});A(I("ipsos-no"),{position:"absolute",left:T.nobutton.left+"px",top:T.nobutton.top+"px"});}var AC=function(){L();P=window.setInterval(L,200);E();G=i(S,"width");A(S,{width:"auto"});l(s);l(M);J("accuracy (now - ipend)",(new Date().getTime())-Z);};y(I("ipsos-message").getElementsByTagName("img"),AC);},dismiss:function(AB){window.clearInterval(P);P=null;l(M);l(s);A(S,{width:G});c();E();X("ipcounter",null,{path:"/"});X("iplength",null,{path:"/"});X("ipstart",null,{path:"/"});X("ipend",null,{path:"/"});if(AB){X("ipsos-prompted","true",{path:"/",expires:T.promptagain*7});}else{X("ipsos-prompted","true",{path:"/",expires:T.promptagain/2*7});}},getCountdown:function(){return Math.round((Z-v)/1000);},getCountdownPercent:function(){return Math.round(this.getCountdown()/o*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);}};}
