/*! Copyright 2009,2010 the Rubicon Project. All Rights Reserved.

No permissio n is granted to use, copy or extend this code */ oz_partner = "rubicon"; function RubiconInsight(){this.config={statichost:"http://tap-cdn.rubiconproject .com",hosts:{insight:"http://tap.rubiconproject.com",valuation:"http://anvil.rub iconproject.com",stats:"http://tap.rubiconproject.com"}};this.default_context={o z_partner:"rubicon",oz_partner_user_id:null,oz_partner_channel:null,oz_partner_t racking:null,oz_ad_slot_size:null,oz_ad_slot_sizes:null,oz_rtb_demand:true,oz_pr ice_bands:[0,5,20,50,100,200,400],oz_price_fuzz:{bias:0,scale:1.05},oz_api:"insi ght",oz_api_key:null,oz_view:null,oz_ad_server:null,oz_callback:null,oz_estimati on_mode:"full",stats_sample:100,coeffs_sample:0,min_pacing:0.5,allow_uncapped:tr ue,rtb_cap:20}; this.context=null;this.init=function(A){try{if(A){this.context=this.mergePropert ies(A,this.default_context);}else{this.context=this.default_context;}if(this.con text.oz_host&&this.context.oz_api){this.config.hosts[this.context.oz_api]=this.c ontext.oz_host;}if(this.context.oz_statichost){this.config.statichost=this.conte xt.oz_statichost; }if(typeof oz_insight_config!="undefined"&&this.context.oz_api){this.context=thi s.mergeProperties(oz_insight_config[this.context.oz_api],this.context);}if(typeo f oz_insight_config_site!="undefined"&&this.context.oz_api){this.context=this.me rgeProperties(oz_insight_config_site[this.context.oz_api],this.context); }}catch(B){}};this.trim=function(A){return A.replace(/^\s+|\s+$/g,"");};this.mer geProperties=function(B,A){if(typeof (B)=="undefined"||!B){return A;}if(typeof ( A)=="undefined"||!A){return new Object();}for(var C in A){if(!A.hasOwnProperty(C )){continue;}if(typeof B[C]=="undefined"){B[C]=A[C];}}return B; };this.copyProperties=function(B,C){if(typeof B=="undefined"||!B){return C;}for( var A in B){C[A]=B[A];}return C;};this.addParam=function(A,B){if(B){return"&"+A+ "="+B;}return"";};this.start=function(){if(this.context.oz_api=="insight"){this. fetchInsight();}if(this.context.oz_api=="valuation"){this.fetchValuation(); }};this.fetchInsight=function(){var A;if(this.insightRetrieved){return ;}this.in sightRetrieved=true;try{A=this.config.hosts.insight+"/partner/agent/"+this.conte xt.oz_partner+"/"+this.context.oz_api+".js?";if(this.context.oz_api_key){A+="&ak ="+this.context.oz_api_key;}if(this.context.oz_partner_user_id){A+="&afu="+this. context.oz_partner_user_id; }if(this.context.oz_partner_channel){A+="&pc="+this.context.oz_partner_channel;} if(this.context.oz_partner_tracking){A+="&ptc="+this.context.oz_partner_tracking ;}if(this.context.oz_view){A+="&uv="+this.context.oz_view;}if(this.context.oz_ad _server){A+="&as="+this.context.oz_ad_server;}A+="&cb=oz_onInsightLoaded"; try{if(this.oz_source.referrer){host=this.oz_source.referrer.split("/")[2];}if(h ost&&(host!=this.oz_source.location.host)){A+="&rd="+host;}}catch(B){}document.w rite("<scr"+"ipt type='text/javascript' src='"+A+"'></scr"+"ipt>");}catch(B){}}; this.ad_sizes={"120/160":"22","120x240":"12","120x60":"6","120x600":"8","120x90" :"5","125x125":"7","160x600":"9","160x90":"24","180x150":"11","180x90":"25","1x1 ":"30","200x200":"13","200x90":"26","234x60":"3","240x400":"17","250x250":"14"," 300x100":"19","300x250":"15","300x600":"10","300x850":"29","336x280":"16","468/7 28":"21","468x15":"27","468x60":"1","728x15":"28","728x90":"2","88x31":"4","Pop" :"20"}; this.getAdSizeById=function(B){for(var A in this.ad_sizes){if(!this.ad_sizes.has OwnProperty(A)){continue;}if(this.ad_sizes[A]==B){return A;}}return null;};this. getPriceBands=function(){if(typeof (this.context.oz_price_bands)=="string"){this .context.oz_price_bands=this.context.oz_price_bands.replace(/ /g,"").split(","); }return this.context.oz_price_bands;};this.fetchValuation=function(){var B;if(th is.valuationRetrieved){return ;}this.valuationRetrieved=true;try{B=this.config.h osts.valuation+"/a/api/market.js?";if(this.context.oz_site){var D=this.context.o

z_site.split("/")[0];var A=this.context.oz_site.split("/")[1]; B+="&account_id="+D;B+="&site_id="+A;}if(this.context.oz_zone){B+="&zone_id="+th is.context.oz_zone;}B+="&rtb_model=1";B+="&cb=oz_onValuationLoaded";try{var E;if (this.oz_source.referrer){E=this.oz_source.referrer.split("/")[2];}if(E&&(E!=thi s.oz_source.location.host)){B+="&rd="+E;}}catch(F){}if(this.context.oz_ad_size_i d){this.context.oz_ad_slot_size=this.getAdSizeById(this.context.oz_ad_size_id); }else{this.context.oz_ad_size_id=this.ad_sizes[this.context.oz_ad_slot_size];}if (this.context.oz_ad_slot_size){B+="&size_id="+this.context.oz_ad_size_id;documen t.write("<scr"+"ipt type='text/javascript'>rp_request_context = {};</scr"+"ipt>" );document.write("<scr"+"ipt type='text/javascript' src='"+B+"'></scr"+"ipt>"); }else{if(this.context.oz_ad_slot_sizes){for(var C=0;C<this.context.oz_ad_slot_si zes.length;C++){this.context.oz_ad_slot_size=this.context.oz_ad_slot_sizes[C];si ze_url=B+"&size_id="+this.ad_sizes[this.context.oz_ad_slot_sizes[C]];document.wr ite("<scr"+"ipt type='text/javascript'>rp_request_context = { oz_ad_slot_size : ###BOT_TEXT###quot;"+this.context.oz_ad_slot_sizes[C]+'" };</scr'+"ipt>"); document.write("<scr"+"ipt type='text/javascript' src='"+size_url+"'></scr"+"ipt >");}}}}catch(F){}};this.onPageLoad=function(){if(this.pageLoadHandled){return ; }this.pageLoadHandled=true;};this.getAsQueryTerms=function(A){var C="";if(typeof A!="undefined"&&A){for(var B in A){var D;if(!A.hasOwnProperty(B)){continue; }if(typeof A[B]=="object"){continue;}D=new String(A[B]);D=D.replace(/\s/g,"+");D =D.replace(/&/g,"%26");C+="&"+B+"="+D;}}return C;};this.getAsDFPKeyValues=functi on(A){var D="";if(typeof A!="undefined"&&A){for(var B in A){var F;var E;if(!A.ha sOwnProperty(B)){continue;}E=A[B];if(typeof E!="object"){E=new Array(); E[E.length]=A[B];}for(var C=0;C<E.length;C++){F=new String(E[C]);if(F.length>0){ F=F.replace(/\s/g,"%20");F=F.replace(/&/g,"%26");D+=";"+B+"="+F;}}}}return D;};t his.getAsAdTechKeyValues=function(A){var D="";if(typeof A!="undefined"&&A){for(v ar B in A){var F;var E;if(!A.hasOwnProperty(B)){continue;}E=A[B]; if(typeof E!="object"){E=new Array();E[E.length]=A[B];}D+=";kv"+B+"=";for(var C= 0;C<E.length;C++){F=new String(E[C]);if(F.length>0){F=F.replace(/\s/g,"%20");F=F .replace(/&/g,"%26");D+=F;if(C<E.length-1){D+=":";}}}}}return D;};this.normalize AttributeValue=function(A){return A;};this.normalize=function(A){var B; for(B in A){if(!A.hasOwnProperty(B)){continue;}if(typeof A[B]=="string"){A[B]=th is.normalizeAttributeValue(A[B]);}else{if(typeof A[B]=="object"){this.normalize( A[B]);}}}return A;};this.genericAdServerHookInsight=function(B,E){var A=B.insigh t||{};try{for(var C in A){var G;var F;if(!A.hasOwnProperty(C)){continue; }F=A[C];if(typeof F!="object"){F=new Array();F[F.length]=A[C];}for(var D=0;D<F.l ength;D++){G=new String(F[D]);if(G.length>0){E(C,G);}}}}catch(H){}};this.setDFPT argeting=function(A,B){if(typeof GA_googleAddAttr=="function"){GA_googleAddAttr( A,B);}else{if(typeof googletag!="undefined"){googletag.cmd.push(function(){googl etag.pubads().setTargeting(A,B); });}}};this.gamAdServerHookInsight=function(B){var A=this;this.genericAdServerHo okInsight(B,function(C,D){D=D.replace(//g,"plus");D=D.replace(/[^\w\d-_\.]+/g, "");D=D.substring(0,40);A.setDFPTargeting(C,D);});};this.gam1AdServerHookInsight =function(B){var A=this;this.genericAdServerHookInsight(B,function(C,D){D=D.repl ace(//g,"plus"); D=D.replace(/[^\w\d-_\.]+/g,"");D=D.substring(0,10);A.setDFPTargeting(C,D);});}; this.gam2AdServerHookInsight=function(B){var A=this;this.genericAdServerHookInsi ght(B,function(C,D){D=D.replace(//g,"plus");D=D.replace(/[^\w\d-_\.]+/g,"");D= D.substring(0,10);C=C.substring(0,10);A.setDFPTargeting(C,D); });};this.gptAdServerHookInsight=function(B){var A=this;this.genericAdServerHook Insight(B,function(C,D){D=D.replace(//g,"plus");D=D.replace(/[^\w\d-_\.]+/g,"" );D=D.substring(0,10);C=C.substring(0,10);A.setDFPTargeting(C,D);});};this.onIns ightLoaded=function(C){try{var A=C.insight;var E;this.normalize(A); if(C.context.oz_ad_server&&typeof this[C.context.oz_ad_server.toLowerCase()+"AdS erverHookInsight"]=="function"){this[C.context.oz_ad_server.toLowerCase()+"AdSer verHookInsight"](C);}var G=new Array();for(E in A){if(!A.hasOwnProperty(E)){cont inue;}G[G.length]=E;}if(G.length>0&&((Math.random()*100)<this.context.stats_samp le)){var D=""; D+=this.config.hosts.stats+"/stats/insight?";D+=this.addParam("p",this.context.o z_partner);D+=this.addParam("ak",this.context.oz_api_key);if(C.context.oz_partne

r_channel){D+=this.addParam("pc",C.context.oz_partner_channel);}else{if(this.con text.oz_partner_channel){D+=this.addParam("pc",this.context.oz_partner_channel); }}D+=this.addParam("ptc",this.context.oz_partner_tracking);D+=this.addParam("api ",this.context.oz_api);D+=this.addParam("uv",this.context.oz_view);D+=this.addPa ram("as",this.context.oz_ad_server);D+=this.addParam("upn",G.join(","));setTimeo ut((function(I){return function(){new Image().src=I;};})(D),1000); }if(this.context.use_stats){var B=(window!=top);var D=this.config.hosts.stats+"/ stats/inventory?";D+=this.addParam("p",this.context.oz_partner);D+=this.addParam ("ak",this.context.oz_api_key);if(C.context.oz_partner_channel){D+=this.addParam ("pc",C.context.oz_partner_channel);}else{if(this.context.oz_partner_channel){D+ =this.addParam("pc",this.context.oz_partner_channel); }}D+=this.addParam("ptc",this.context.oz_partner_tracking);D+=this.addParam("api ","inventory");if(B){D+=this.addParam("aso",(B?"framed":""));}if(document.referr er){host=document.referrer.split("/")[2];}if(host&&(host!=document.location.host )){D+=this.addParam("rd",host);}setTimeout((function(I){return function(){new Im age().src=I; };})(D),1000);}}catch(F){}try{var A=C.insight;var H=this.context.oz_callback;if( H&&typeof H=="function"){H(A);}if(H&&typeof H=="string"&&window[H]&&typeof windo w[H]=="function"){window[H](A);}}catch(F){}};this.createCookie=function(C,D,E){i f(E){var B=new Date();B.setTime(B.getTime()+(E*24*60*60*1000)); var A="; expires="+B.toGMTString();}else{var A="";}document.cookie=C+"="+D+A+"; path=/";};this.createTodayCookie=function(C,D){var B=new Date();B=new Date(B.get Time()+(86400*1000));B=new Date(B.getFullYear(),B.getMonth(),B.getDate(),0,0,0,0 );var A="; expires="+B.toGMTString();document.cookie=C+"="+D+A+"; path=/"; };this.readCookie=function(B){var D=B+"=";var A=document.cookie.split(";");for(v ar C=0;C<A.length;C++){var E=A[C];while(E.charAt(0)==" "){E=E.substring(1,E.leng th);}if(E.indexOf(D)==0){return E.substring(D.length,E.length);}}return null;};t his.getImpressionCount=function(A,B){var C=this.readCookie("_trp_hit_"+A+"_"+B); if(!C){C=this.readCookie("_trp_hit_"+B);if(C){this.createCookie("_trp_hit_"+B,C, -1);}}if(C){C=Number(C);}return Math.max(C||1,1);};this.setImpressionCount=funct ion(C,A,B){this.createTodayCookie("_trp_hit_"+A+"_"+B,C);};this.selectBestAd=fun ction(C){var A={cpm:0};var F;var E;var H;var G=this.getImpressionCount(this.cont ext.oz_site,this.context.oz_ad_slot_size); if(this.context.oz_estimation_mode=="piggyback"){G-=1;}for(var D=0;D<C.valuation .ads.length;D++){F=C.valuation.ads[D];if(F.type!="partner"&&F.type!="rtb"&&F.typ e!="static_bid"){continue;}if(F.cpm<0){continue;}if(F.pacing&&F.pacing<this.cont ext.min_pacing){continue;}if(F.fct!="open"){if(typeof F.fcl=="undefined"&&F.type =="partner"&&!this.context.allow_uncapped){break; }E=(typeof F.fcl=="undefined")?(F.type=="rtb"?1:0):F.fcl;E-=(F.fcc||0);H=(F.fcp| |86400);if(E==0){continue;}var B=Math.ceil(E*(H/86400));G-=B;if(G>0){continue;}} A=F;if((F.type=="rtb"||F.type=="static_bid")&&(D<C.valuation.ads.length-1)){A.bi d=F.cpm;A.cpm=C.valuation.ads[D+1].cpm;}break;}A.hit=this.getImpressionCount(thi s.context.oz_site,this.context.oz_ad_slot_size); if(this.context.oz_estimation_mode=="piggyback"){A.hit-=1;}return A;};this.gener ateEstimateForAllAds=function(A){for(var B=0;B<A.valuation.ads.length;B++){ad=A. valuation.ads[B];ad.estimate=this.generateEstimate(ad);}};this.generateEstimate= function(B){var G={tier:0};if(B){var A=0;var E=this.getPriceBands(); var C=this.context.oz_price_fuzz.bias||0;var F=this.context.oz_price_fuzz.scale| |1;for(var D=0;D<E.length;D++){if(((C+(F*B.cpm))*100)>=E[D]){A=E[D];}}G={tier:A, cpm:B.cpm,hit:B.hit,type:B.type};if(B.ad_id){G.ad_id=B.ad_id;}}return G;};this.t ranformRtbCoeffs=function(E){var D=[];for(var F in E){if(!E.hasOwnProperty(F)){c ontinue; }var B=E[F];var C={nid:F,baseline:B.vec[0],session:{10:B.vec[1]||0,30:B.vec[2]|| 0,100:B.vec[3]||0,1000:B.vec[4]||0},historical:{cpm:B.vec[29],probability:B.vec[ 30]},coeffs:B};var A=B.vec.slice(5,29);if(A.length==24){C.hours=A;}D[D.length]=C ;}return D;};this.convertToAds=function(C,G,A){var E=[];for(var D in C){if(!C.ha sOwnProperty(D)){continue; }var B=C[D];var F={nid:B.nid,type:"rtb",algorithm:"rtb-session",fcl:this.context .rtb_cap,cpm:B.baseline,coeffs:B.coeffs};for(depth in B.session){if(!B.session.h asOwnProperty(depth)){continue;}if(G<depth){F.cpm+=B.session[depth];break;}}if(B

.hours&&(typeof A!="undefined")&&A>=0&&A<=23){F.cpm+=B.hours[A]; }if((B.historical.cpm>0)&&Math.random()<B.historical.probability){F.cpm=B.histor ical.cpm;F.algorithm="rtb-historical";}F.cpm=Math.min(Math.max(F.cpm,0),100);E[E .length]=F;}return E;};this.adjustAds=function(B){for(var A=0;A<B.length;A++){ad =B[A];ad.ecpm=ad.cpm;ad.cpm=ad.dcpm?Math.min(ad.ecpm,ad.dcpm):ad.ecpm; }};this.onValuationLoaded=function(G){try{var M=G.valuation;var D;G.context=G.co ntext||this.context;if(typeof rp_request_context!="undefined"){this.copyProperti es(rp_request_context,G.context);}if(G.valuation.rtb_coeffs&&this.context.oz_rtb _demand){var C=this.tranformRtbCoeffs(G.valuation.rtb_coeffs); var A=this.getImpressionCount(this.context.oz_site,this.context.oz_ad_slot_size) ;if(this.context.oz_estimation_mode=="piggyback"){A-=1;}var H=new Date().getHour s();var F=this.convertToAds(C,A,H);G.valuation.ads=F.concat(G.valuation.ads);}th is.adjustAds(G.valuation.ads);G.valuation.ads=G.valuation.ads.sort(function(P,O) {return(O.cpm-P.cpm); });this.generateEstimateForAllAds(G);G.valuation.best_ad=this.selectBestAd(G);G. valuation.estimate=this.generateEstimate(G.valuation.best_ad);if(this.context.oz _estimation_mode!="piggyback"){this.setImpressionCount(1+this.getImpressionCount (this.context.oz_site,this.context.oz_ad_slot_size),this.context.oz_site,this.co ntext.oz_ad_slot_size); }var E="";var K={size:"size",tier:"tier",cpm:"cpm"};if(this.context.oz_ad_slot_s izes){if(G.context.oz_ad_server=="gam2"){E="-"+this.context.oz_ad_slot_size;K={t ier:"rt",cpm:"rc"};}if(G.context.oz_ad_server=="gpt"){E="-"+this.context.oz_ad_s lot_size;K={tier:"rt",cpm:"rc"};}rp_valuation_cb=rp_valuation_cb||{estimates:{}} ; G.valuation.estimate.size=this.context.oz_ad_slot_size;G.insight={};for(D in G.v aluation.estimate){if(!G.valuation.estimate.hasOwnProperty(D)){continue;}if(K[D] ){G.insight[K[D]+E]=G.valuation.estimate[D];}}rp_valuation_cb.estimates[G.valuat ion.estimate.size]=G.insight;rp_valuation=G.valuation;rp_valuation.estimates=rp_ valuation_cb.estimates; }else{G.insight={};for(D in G.valuation.estimate){if(!G.valuation.estimate.hasOw nProperty(D)){continue;}if(K[D]){G.insight[K[D]+E]=G.valuation.estimate[D];}}}if (G.context.oz_ad_server&&typeof this[G.context.oz_ad_server.toLowerCase()+"AdSer verHookInsight"]=="function"){this[G.context.oz_ad_server.toLowerCase()+"AdServe rHookInsight"](G); }var L=new Array();for(D in M){if(!M.hasOwnProperty(D)){continue;}L[L.length]=D; }if(L.length>0&&((Math.random()*100)<this.context.stats_sample)){var B="";B+=thi s.config.hosts.stats+"/stats/valuation?";B+=this.addParam("p",this.context.oz_pa rtner);B+=this.addParam("ak",this.context.oz_api_key);B+=this.addParam("pc",this .context.oz_site); B+=this.addParam("ptc",this.context.oz_zone);B+=this.addParam("api",this.context .oz_api);B+=this.addParam("as",this.context.oz_ad_server);B+=this.addParam("asz" ,this.context.oz_ad_slot_size);B+=this.addParam("tier",G.valuation.estimate.tier );B+=this.addParam("cpm",G.valuation.estimate.cpm);B+=this.addParam("ecpm",G.val uation.estimate.ecpm); B+=this.addParam("hit",G.valuation.estimate.hit);B+=this.addParam("type",G.valua tion.estimate.type);B+=this.addParam("iid",G.context.oz_impression_id);B+=this.a ddParam("ad",G.valuation.estimate.ad_id);B+=this.addParam("rnd",Math.floor((Math .random()*10000)));if(G.valuation.best_ad.coeffs&&((Math.random()*100)<this.cont ext.coeffs_sample)){B+=this.addParam("rc",G.valuation.best_ad.coeffs.vec.join(", ")); }B+=this.addParam("rtc",(G.valuation.rtb_coeffs?1:0));if(G.valuation.best_ad.alg orithm){B+=this.addParam("rta",G.valuation.best_ad.algorithm);}if(G.context.oz_i mpression_id){setTimeout((function(O){return function(){new Image().src=O;};})(B ),1000);}else{setTimeout((function(O,P){return function(){if(typeof oz_ad_contex t!="undefined"&&oz_ad_context[P]&&oz_ad_context[P].iid){O+="&iid="+oz_ad_context [P].iid; }new Image().src=O;};})(B,this.context.oz_ad_size_id||this.ad_sizes[this.context .oz_ad_slot_size]),2000);}}}catch(J){}try{var I=G.insight;var N=this.context.oz_ callback;if(N&&typeof N=="function"){N(I);}if(N&&typeof N=="string"&&window[N]&& typeof window[N]=="function"){window[N](I);}}catch(J){}};}function oz_insight(E)

{try{var D=new RubiconInsight(); var C=new Object();var G=["oz_host","oz_statichost","oz_api","oz_api_key","oz_pa rtner","oz_partner_user_id","oz_partner_channel","oz_partner_tracking","oz_site" ,"oz_zone","oz_ad_slot_size","oz_ad_slot_sizes","oz_rtb_demand","oz_price_bands" ,"oz_price_fuzz","oz_view","oz_ad_server","oz_callback","oz_impression_id","oz_a d_size_id","oz_estimation_mode"]; var A;D.oz_source=document;for(var B=0;B<G.length;B++){A=G[B];if(typeof window[A ]!="undefined"){C[A]=window[A];}}D.init(C);oz_insight_partner_hook(D);window.oz_ onInsightLoaded=function(H){D.onInsightLoaded(H);};window.oz_onValuationLoaded=f unction(H){D.onValuationLoaded(H);};D.start();if(E||D.autorun){D.onPageLoad(); }}catch(F){}}function oz_insight_partner_hook(A){return A;}function oz_insight_a dserver_hook(A){return A;}try{if(typeof rp_valuation_cb=="undefined"){var rp_val uation_cb;}}catch(e){} /* The requested resource (/oz/scripts/partners/rubicon/insight_hooks.js) i s not available */ oz_insight_config_site = {"valuation":{"oz_price_bands":[0,5,10,25,50,75,100,150 ,200],"allow_uncapped":true}} oz_insight();