var googletag=googletag||{};googletag.cmd=googletag.cmd||[];window.pbjs=window.pbjs||{};window.pbjs.que=window.pbjs.que||[];var prebidEnabled=false;if(typeof window.prebidEnabled_flag!=="undefined"){prebidEnabled=window.prebidEnabled_flag;}
if(typeof window.prebidEnabled!=="undefined"){prebidEnabled=window.prebidEnabled;}
window['ga']=window['ga']||function(){(window['ga'].q=window['ga'].q||[]).push(arguments),window['ga'].l=1*new Date();};(function(){var PREBID_TIMEOUT=500;if(typeof window.prebidtimeout!=="undefined"){PREBID_TIMEOUT=window.prebidtimeout;}
pbjs.CustomTrackPrebidInfo=function(responses){var responseCounts={};var totalCPM={};var totalLatency={};var timeout={};for(var i=0;i<pbjs.adUnits.length;i++){var bids=pbjs.adUnits[i].bids;for(var j=0;j<bids.length;j++){var bidder=bids[j].bidder;responseCounts[bidder]=0;totalCPM[bidder]=0;totalLatency[bidder]=0;timeout[bidder]=true;}}
for(var slot in responses){if(responses.hasOwnProperty(slot)){responses[slot].bids.forEach(function(bid){timeout[bid.bidderCode]=false;if(bid.statusMessage==="Bid available"){responseCounts[bid.bidderCode]+=1;totalCPM[bid.bidderCode]+=bid.cpm;totalLatency[bid.bidderCode]+=bid.timeToRespond;}});}}
setTimeout(function(){for(var network in responseCounts){if(responseCounts.hasOwnProperty(network)){if(!timeout[network]){if(responseCounts[network]>0){var cpmAvg=Math.floor(100*totalCPM[network]/responseCounts[network]);var latencyAvg=Math.floor(totalLatency[network]/responseCounts[network]);if(typeof dataLayer!="undefined"){dataLayer.push({'event':'eventPreBidTracker','eventCategory':"prebid",'eventAction':"cpm",'eventLabel':network,'eventValue':cpmAvg,'eventNonInt':true});dataLayer.push({'event':'eventPreBidTracker','eventCategory':"prebid",'eventAction':'latency','eventLabel':network,'eventValue':latencyAvg,'eventNonInt':true});}}else{if(typeof dataLayer!="undefined"){dataLayer.push({'event':'eventPreBidTracker','eventCategory':"prebid",'eventAction':'nobid','eventLabel':network,'eventValue':1,'eventNonInt':true});}}}else{if(typeof dataLayer!="undefined"){dataLayer.push({'event':'eventPreBidTracker','eventCategory':"prebid",'eventAction':'timeout','eventLabel':network,'eventValue':1,'eventNonInt':true});}}}}},3000);};function initAdserver(){if(pbjs.initAdserverSet)return;(function(){var gads=document.createElement('script');gads.async=true;gads.type='text/javascript';var useSSL='https:'==document.location.protocol;gads.src=(useSSL?'https:':'http:')+'//www.googletagservices.com/tag/js/gpt.js';var node=document.getElementsByTagName('script')[0];node.parentNode.insertBefore(gads,node);})();pbjs.initAdserverSet=true;}
setTimeout(initAdserver,PREBID_TIMEOUT);if(prebidEnabled){(function(){var d=document,pbs=d.createElement("script");pbs.type="text/javascript";pbs.async=true;pbs.src='/js/prehead/prebid.js';var target=document.getElementsByTagName("head")[0];target.insertBefore(pbs,target.firstChild);})();window.pbjs_request_queue=function(){var queue=[];var pbjs_ready=false;function init(){pbjs_ready=true;processNext();}
function processNext(){if(!pbjs_ready){return;}
if(queue.length===0){return;}
pbjs.que.push(queue[0]);}
function push(fn){queue.push(fn);if(queue.length===1){processNext();}}
function shift(){queue.shift();processNext();}
function refreshBySlotName(slotName){push(function(){var start;pbjs.requestBids({timeout:PREBID_TIMEOUT,adUnitCodes:[slotName],bidsBackHandler:function(){pbjs.setTargetingForGPTAsync(slotName);googletag.pubads().refresh([window.adslots[slotName]]);setTimeout(shift,(1+PREBID_TIMEOUT-(+new Date())+start));}});start=+new Date();});}
return{'refreshBySlotName':refreshBySlotName,'init':init};}();pbjs.que.push(function(){pbjs.bidderSettings=window.prebiddersettings;pbjs.addAdUnits(window.prebidders);pbjs.requestBids({adUnitCodes:window.prebidadslotsarrray,timeout:PREBID_TIMEOUT,bidsBackHandler:function(bidResponses){initAdserver();pbjs_request_queue.init();}});});}else{initAdserver();}})();window.adslots={};window.adrefreshslots=new Array();window.maplayershown=new Array();window.checkdata_addisplayed={};var processDFP={aId:"",dfpDivs:new Array(),slotTags:'',pageLevelTargets:'',adSize:'',adIU:'',adIUBakup:'',slotsdefined:false,handle:0,adproduct:'',is_alert:(function(){return document.getElementsByTagName('head')[0].className.match('takeover-state')?1:0;})(),disable_takeover:(function(){return document.getElementsByTagName('head')[0].className.match('disable-takeover')?1:0;})(),render:function(iu,adspecs){if(typeof window._config.dfp_adunit_ids!=="undefined"){dfpadunits=JSON.parse(window._config.dfp_adunit_ids);var user_lang="en";var user_country="ca";var user_locale="en_ca";var pelm_ip=unescape(_fd.k('pelm_ip'));if(pelm_ip=="null"){var pelm_user_domain=unescape(_fd.k('pelm_user_domain'));if(pelm_user_domain=="null"){}else{user_locale=pelm_user_domain;}}else{pelm_ip=JSON.parse(pelm_ip);if(typeof pelm_ip.country!='undefined'){user_country=pelm_ip.country;}
if(user_country){user_country=user_country.toLowerCase();}
if(user_country=="uk"){user_country="gb";}
if(user_country=="null"){}else{if(typeof window._config.lang!=="undefined"){user_lang=window._config.lang;user_locale=user_lang+"_"+user_country;}}}
for(var key in dfpadunits){if(typeof window._config.lang!=="undefined"&&window._config.lang=="en"){if(typeof window._config.locale!=="undefined"){iu=iu.replace(dfpadunits[window._config.locale],dfpadunits['default']);}
if(key==user_locale){iu=iu.replace(dfpadunits['default'],dfpadunits[user_locale]);break;}}else{if(key==user_locale){iu=iu.replace(dfpadunits[key],dfpadunits[user_locale]);break;}}}}
this.adIU=iu;var iuarray=iu.split("/");processDFP.adproduct=iuarray[iuarray.length-1];this.adIUBakup=iu;for(var key in adspecs){var adspecarray=adspecs[key].split(":");var aId=adspecarray[0];var adsize=adspecarray[1];var pos=adspecarray[2];this.adIU=this.adIUBakup;if(typeof(adspecarray[3])!=='undefined'){var adIUarray=this.adIU.split("/");this.adIU="/"+adIUarray[1]+"/"+adIUarray[2]+"/"+adspecarray[3];}
if((aId||typeof aId!=='undefined')&&(pos||typeof pos!=='undefined')){processDFP.dfpDivs.push(aId);processDFP.getSlotTag(aId,adsize,pos);}}
if(processDFP.slotTags!=''){if((window._config['ajax_weather'])&&(typeof window.placecode!=='undefined'&&window.placecode!==null)){var ckd_int=(typeof window._config.dfpcheckdatainterval!=="undefined")?window._config.dfpcheckdatainterval:100;window._config.dfpcheckdatactr=(typeof window._config.dfp_checkdata_ctr!=="undefined")?window._config.dfp_checkdata_ctr:1;window._config.adretries=0;processDFP.handle=setInterval(function(){processDFP.checkData();},ckd_int);}else{processDFP.renderHead();}}
window.dfpadiu=this.adIU;},renderTag:function(id){if(this.slotTags!=''){document.write('<scr'+'ipt type="text/javaScript"> googletag.cmd.push(function() { googletag.display("'+id+'");});</scr'+'ipt>');}},checkData:function(){if((typeof _adwxdata!=='undefined'&&_adwxdata&&typeof _adwxdata.d!=='undefined')&&(window._config.adretries<window._config.dfpcheckdatactr)){if(_adwxdata.d){processDFP.renderHead();processDFP.renderAd();}}else{if(window._config.adretries>window._config.dfpcheckdatactr){processDFP.renderHead();processDFP.renderAd();}}
window._config.adretries++;},renderAd:function(){for(var i=0;i<processDFP.dfpDivs.length;i++){if((processDFP.dfpDivs[i].indexOf('topbanner')!==-1)||(processDFP.dfpDivs[i].indexOf('bigbox')!==-1)){if(typeof window.checkdata_addisplayed[processDFP.dfpDivs[i]]!==true){window.checkdata_addisplayed[processDFP.dfpDivs[i]]=true;googletag.cmd.push(function(){googletag.display(processDFP.dfpDivs[i]);});}}}
var adslots_displayed={};for(var i=0;i<processDFP.dfpDivs.length;i++){if((processDFP.dfpDivs[i].indexOf('topbanner')!==-1)||(processDFP.dfpDivs[i].indexOf('bigbox')!==-1)){if(document.getElementById(processDFP.dfpDivs[i])){var adcontent=document.getElementById(processDFP.dfpDivs[i]);adslots_displayed[processDFP.dfpDivs[i]]=false;if(contains(document,adcontent)==true&&adcontent.innerHTML!==''){var adcontentHTML=adcontent.innerHTML;adslots_displayed[processDFP.dfpDivs[i]]=true;}}}}
if(adslots_displayed['div-gpt-ad-topbanner']&&adslots_displayed['div-gpt-ad-bigbox']){clearInterval(processDFP.handle);}
if(window._config.platform=="mobile"&&adslots_displayed['div-gpt-ad-bigbox']){if(adcontentHTML.indexOf('google_ads')!==-1&&adcontentHTML.indexOf('iframe')!==-1){clearInterval(processDFP.handle);}}},renderHead:function(){window.btfBillboard={flags:{bigBox:false,topBanner:false}}
var scriptText="googletag.cmd.push(function() {";scriptText+="\n "+processDFP.slotTags;processDFP.getPageLevelTargetting();scriptText+="\n "+processDFP.pageLevelTargets;if(prebidEnabled){scriptText+="pbjs.que.push(function(){pbjs.setTargetingForGPTAsync();});";scriptText+="if(typeof pbjs.getBidResponses === 'function'){pbjs.CustomTrackPrebidInfo(pbjs.getBidResponses());}";}
scriptText+="\n googletag.pubads().collapseEmptyDivs();";if(scriptText.indexOf('div-gpt-ad-companion')!=-1){scriptText+="\n googletag.companionAds().setRefreshUnfilledSlots(true);";}
scriptText+="\n googletag.pubads().addEventListener('slotRenderEnded', function(event) {  ";scriptText+="\n var currentSlotId = event.slot.getSlotElementId();";scriptText+="\n if(currentSlotId=='div-gpt-ad-bigbox'){";scriptText+="\n window.bigboxrendered=true;";scriptText+="\n if ((event['size']!='300,600')&&(event['size']!='300,1050')) { window.btfBillboard.flags.bigBox=true; }"
scriptText+="\n else { window.btfBillboard.flags.bigBox=false; document.documentElement.classList.add('gpt-bigbox-billboard'); }";scriptText+="\n }";scriptText+="\n if((currentSlotId=='div-gpt-ad-topbanner') && (window.adtakeover!==true)){ window.btfBillboard.flags.topBanner=true; }";scriptText+="\n if(window.btfBillboard.flags.topBanner===true &&  window.btfBillboard.flags.bigBox===true){"
scriptText+="\n window.lowerbox_size_mapping = googletag.sizeMapping().addSize([1,1], [[300, 250],[300, 600]]).build(); ";scriptText+="\n if(window.adslots && window.adslots['div-gpt-ad-lowerbox']){window.adslots['div-gpt-ad-lowerbox'].defineSizeMapping(window.lowerbox_size_mapping)} ";scriptText+="\n }";scriptText+="\n var tempSlot = window.stickyAds[currentSlotId]";scriptText+="\n var waitThen=setTimeout(function(){";scriptText+="\n if(tempSlot){";scriptText+="\n var stickyDuration = Number(tempSlot.duration) || 2000 //Absolute fallback to 2 seconds";scriptText+="\n var stickyLifespan = Number(tempSlot.lifespan) || 2000 //Absolute fallback to 2 seconds";scriptText+="\n var now = new Date().getTime();";scriptText+="\n var then = now + stickyDuration";scriptText+="\n var doomsday = (stickyLifespan >-1) ? now + stickyLifespan : -1";scriptText+="\n window.stickyAds[currentSlotId].id = currentSlotId;";scriptText+="\n window.stickyAds[currentSlotId].slot = tempSlot;";scriptText+="\n window.stickyAds[currentSlotId].birthdate = now;";scriptText+="\n window.stickyAds[currentSlotId].expirationdate = then;";scriptText+="\n window.stickyAds[currentSlotId].suicidedate = doomsday;";scriptText+="\n window.stickyAds[currentSlotId].init();";scriptText+="\n }";scriptText+="\n }, 500);";scriptText+="\n });";scriptText+="\n googletag.enableServices();";scriptText+="\n });";var scriptarray=scriptText.split('addService(googletag.pubads());');var script=document.createElement('script');script.type='text/javascript';script.text=scriptText;var headNode=document.getElementsByTagName('head')[0];headNode.appendChild(script);processDFP.slotsdefined=true;if(document.getElementById('renderdfptags')){document.getElementById('renderdfptags').style.display="none";}
window.adserviceenabled=true;},getSlotTag:function(aId,adsize,pos){var stext='';if(typeof pos!='undefined'){stext="window.adslots['"+aId+"']=googletag.defineSlot('"+this.adIU+"',"+adsize+",'"+aId+"')";if(pos=='bottom'||processDFP.is_alert||processDFP.disable_takeover){stext+=".setCategoryExclusion('_Run Only Above The Fold')";}
if(typeof JSON==='object'&&typeof JSON.parse==='function'){try{var se=JSON.parse(window._config.set_categoryexclusion_json);for(var x in se){if(se[x].ad_product==processDFP.adproduct&&se[x].divname==aId){stext+=".setCategoryExclusion('_Run Only Above The Fold')";}}}catch(e){}}
stext+=".setTargeting('pos','"+pos+"')";if(pos=='top'&&typeof _bd_!='undefined'){stext+=".setTargeting('sd_test','"+_bd_.timeout+"')";}
if(aId=="div-gpt-ad-companion"){stext+=".addService(googletag.companionAds())";}
if(aId=="div-gpt-ad-lowerbox"||aId=="div-gpt-ad-lowerbanner"){stext+=".setTargeting('tar','false')";}
if(window.stickyAds&&window.stickyAds["div-gpt-ad-topbanner"]&&(aId=="div-gpt-ad-topbanner"||aId=="div-gpt-ad-bigbox")){stext+=".setTargeting('sh_test','true')";}}
stext+=".addService(googletag.pubads());";processDFP.slotTags+="\n"+stext;if(aId.indexOf('map')!=-1||aId.indexOf('fullscreen')!=-1){window.adrefreshslots.push(aId);}},getPageLevelTargetting:function(){var stext='';if(_ad_conf_global.m.kvb!=''&&_ad_conf_global.m.kvb!=null){stext+="googletag.pubads().setTargeting('g','"+_ad_conf_global.m.kvg+"');"+"\n";}
if(_ad_conf_global.m.kvg!=''&&_ad_conf_global.m.kvg!=null){stext+="googletag.pubads().setTargeting('b','"+_ad_conf_global.m.kvb+"');"+"\n";}
if(typeof _ad_conf!=='undefined'){_ad_conf.to_advars();if(_ad_conf.advars.placecode!=''&&_ad_conf.advars.placecode!=null){stext+="googletag.pubads().setTargeting('location','"+_ad_conf.advars.placecode+"');"+"\n";stext+="googletag.pubads().setTargeting('locationname','"+_ad_conf.advars.ad_location+"');"+"\n";stext+="googletag.pubads().setTargeting('country','"+_ad_conf.advars.countryCode+"');"+"\n";if(_ad_conf.advars.provcode!=''&&_ad_conf.advars.provcode!=null){stext+="googletag.pubads().setTargeting('province','"+_ad_conf.advars.provcode+"');"+"\n";}}else{if(typeof window._config.indexcountry!=="undefined"){stext+="googletag.pubads().setTargeting('country','"+window._config.indexcountry+"');"+"\n";}
if(typeof window._config.indexprov!=="undefined"){stext+="googletag.pubads().setTargeting('province','"+window._config.indexprov+"');"+"\n";}}}
if(typeof _ad_conf=='undefined'){if(typeof window._config.indexcountry!=="undefined"){stext+="googletag.pubads().setTargeting('country','"+window._config.indexcountry+"');"+"\n";}
if(typeof window._config.indexprov!=="undefined"){stext+="googletag.pubads().setTargeting('province','"+window._config.indexprov+"');"+"\n";}
if(typeof window._config.indexlocation!=="undefined"){stext+="googletag.pubads().setTargeting('location','"+window._config.indexlocation+"');"+"\n";}
if(typeof window._config.indexlocationname!=="undefined"){stext+="googletag.pubads().setTargeting('locationname','"+window._config.indexlocationname+"');"+"\n";}}
if(typeof _ad_conf_global!=='undefined'){if(_ad_conf_global.m.kvpostal!=''&&_ad_conf_global.m.kvpostal!=null){stext+="googletag.pubads().setTargeting('postal','"+_ad_conf_global.m.kvpostal+"');"+"\n";stext+="googletag.pubads().setTargeting('c2','"+_ad_conf_global.m.kvc2+"');"+"\n";}}
stext+="googletag.pubads().setTargeting('platform', 'WebSite');"+"\n";if(window._config.platform=="mobile"){stext+="googletag.pubads().setTargeting('platform', 'iPhoneAndroidMobileWeb');"+"\n";}
if(((typeof window._config.kvtest!=="undefined")&&(window._config.kvtest=="TRUE"))||((typeof window._config.kvtest!=="undefined")&&(window._config.kvtest==true))){stext+="googletag.pubads().setTargeting('test', '"+window._config.kvtest+"');"+"\n";}
if(typeof window._config.photocat!=="undefined"){stext+="googletag.pubads().setTargeting('photocat', '"+window._config.photocat+"');"+"\n";}
if(typeof window._config.newscat!=="undefined"&&window._config.newscat!=""&&window._config.newscat.indexOf('_index')<=0&&window._config.newscat!=="news_index"){var newscatarray=window._config.newscat.split(",");var j=newscatarray.length;var newscat="[";for(i=0;i<newscatarray.length;i++)
{newscat+="'"+newscatarray[i]+"'";if(i<j-1){newscat+=",";}}
newscat+="]";stext+="googletag.pubads().setTargeting('newscat', "+newscat+");"+"\n";stext+="googletag.pubads().setTargeting('newsid', '"+window._config.newsid+"');"+"\n";}
if(typeof _ad_conf!=='undefined'){if(_ad_conf.m.kvtemp!=''&&_ad_conf.m.kvtemp!=null){stext+="googletag.pubads().setTargeting('cond','"+_ad_conf.m.kvcond+"');"+"\n";stext+="googletag.pubads().setTargeting('feelslike','"+_ad_conf.m.kvfeelslike+"');"+"\n";stext+="googletag.pubads().setTargeting('flu','"+_ad_conf.m.kvflu+"');"+"\n";stext+="googletag.pubads().setTargeting('humidity','"+_ad_conf.m.kvhumidity+"');"+"\n";stext+="googletag.pubads().setTargeting('pollen','"+_ad_conf.m.kvpollen+"');"+"\n";stext+="googletag.pubads().setTargeting('precip','"+_ad_conf.m.kvprecip+"');"+"\n";stext+="googletag.pubads().setTargeting('pressure','"+_ad_conf.m.kvpressure+"');"+"\n";stext+="googletag.pubads().setTargeting('rainacclt','"+_ad_conf.m.kvrainaccumlt+"');"+"\n";stext+="googletag.pubads().setTargeting('rainaccst','"+_ad_conf.m.kvrainaccumst+"');"+"\n";stext+="googletag.pubads().setTargeting('snowacclt','"+_ad_conf.m.kvsnowaccumlt+"');"+"\n";stext+="googletag.pubads().setTargeting('snowaccst','"+_ad_conf.m.kvsnowaccumst+"');"+"\n";stext+="googletag.pubads().setTargeting('temp','"+_ad_conf.m.kvtemp+"');"+"\n";stext+="googletag.pubads().setTargeting('uvdata','"+_ad_conf.m.kvuvdata+"');"+"\n";stext+="googletag.pubads().setTargeting('visibility','"+_ad_conf.m.kvvisibility+"');"+"\n";stext+="googletag.pubads().setTargeting('windspeed','"+_ad_conf.m.kvwindspeed+"');"+"\n";}
if(_ad_conf.sp.whsnowfall!=''&&_ad_conf.sp.whsnowfall!=null){stext+="googletag.pubads().setTargeting('whistler_last24hr_snow','"+_ad_conf.sp.whsnowfall+"');"+"\n";}
if(_ad_conf.sp.sd_test!=''&&_ad_conf.sp.sd_test!=null){}}
if(typeof window.postalcode!=="undefined"&&window.postalcode!=""){stext+="googletag.pubads().setTargeting('postal','"+window.postalcode.substr(0,3)+"');"+"\n";}
if(typeof window.alertexists!=="undefined"){var alertexists=window.alertexists;if(typeof window._config.alertexists!=="undefined"){if(window._config.alertexists.indexOf("TRUE")>-1){alertexists="TRUE";}}
if(typeof dfp_alerttype!="undefined"){var dfpalertsparm="'"+alertexists+"',"+dfp_alerttype+","+dfp_alert_source+","+dfp_alert_name;stext+="googletag.pubads().setTargeting('warning',["+dfpalertsparm+"]);"+"\n";}else{stext+="googletag.pubads().setTargeting('warning',['"+alertexists+"']);"+"\n";}}
if(typeof window.dfp_contviewed!=="undefined"){stext+="googletag.pubads().setTargeting('contviewed','"+window.dfp_contviewed+"');"+"\n";}
var dfpbrtr=unescape(_fd.ls_get("local","pelm_brtr"));if(dfpbrtr!=="undefined"&&dfpbrtr!==undefined&&dfpbrtr!==null&&dfpbrtr!=="null"){var adbrtrarray=dfpbrtr.split("-");var dfpbrtrstring='';for(i=0;i<adbrtrarray.length;i++){dfpbrtrstring=dfpbrtrstring+"'"+adbrtrarray[i]+"',";}
dfpbrtrstring=dfpbrtrstring.slice(0,dfpbrtrstring.lastIndexOf(","));stext+="googletag.pubads().setTargeting('brtr',["+dfpbrtrstring+"]);"+"\n";}
if(typeof window.AamGpt!='undefined'){stext+="if(typeof AamGpt.getCookie('aam_dfp') != 'undefined'){ \n";stext+="  googletag.pubads().setTargeting(AamGpt.getKey('aam_dfp'),AamGpt.getValues('aam_dfp'));\n";stext+=" }; \n";stext+="if(typeof AamGpt.getCookie('aam_uuid') != 'undefined' ){ \n";stext+="   googletag.pubads().setTargeting('aamId', AamGpt.getCookie('aam_uuid')); \n";stext+="}; \n";}
if(typeof window._config.maps!="undefined"&&typeof window._config.maps.is_regionalmaps!="undefined"&&window._config.maps.is_regionalmaps!="undefined"){if(typeof window._config.maps.dfp_contrycode!="undefined"){stext+="googletag.pubads().setTargeting('country','"+window._config.maps.dfp_contrycode.toLowerCase()+"');"+"\n";}else{stext+="googletag.pubads().setTargeting('country','undefined');"+"\n";}
if(typeof window._config.maps.dfp_provcode!="undefined"){stext+="googletag.pubads().setTargeting('province','"+window._config.maps.dfp_provcode.toLowerCase()+"');"+"\n";}else{stext+="googletag.pubads().setTargeting('country','undefined');"+"\n";}}
processDFP.pageLevelTargets+="\n"+stext;},renderBehaviouralTargetting:function(adbehaviouraltargetting){var dfpbrtr_timestamp=unescape(_fd.k('pelm_brtr_timestamp'));if(dfpbrtr_timestamp=="undefined"||dfpbrtr_timestamp==undefined||dfpbrtr_timestamp==null||dfpbrtr_timestamp=="null"){var currenttimeinsecs=new Date().getTime()/1000;_fd.m("pelm_brtr_timestamp",currenttimeinsecs,30);_fd.ls_set("local","pelm_brtr",'');}
var dfpbrtr=unescape(_fd.ls_get("local","pelm_brtr"));if(dfpbrtr=="undefined"||dfpbrtr==null||dfpbrtr=="null"){dfpbrtr='';}
var adbrtrarray=adbehaviouraltargetting.split("-");for(i=0;i<adbrtrarray.length;i++){if(dfpbrtr.indexOf(adbrtrarray[i])==-1){if(dfpbrtr.length>0){dfpbrtr=dfpbrtr+"-";}
dfpbrtr=dfpbrtr+adbrtrarray[i];}}
if(dfpbrtr!=""){_fd.ls_set("local","pelm_brtr",dfpbrtr);}},refreshad:function(evt){var mapproducts=new Array('radar','satrad','trafficcameras','regional','trafficflow','alerts','highwayforecast','ushighwayforecast','highwayconditions','lightning');var adproducts=new Array('sat_and_rad','sat_and_rad','traffic_cameras','current_weather','traffic_flow','alerts','highway_forecast','us_highway_forecast','highway_conditions','lightning');var fsm=$('html').hasClass('fullscreen-map');if(typeof window.placecodedataparam!=="undefined"){fsm=false;}
if(typeof window.alertexists!=="undefined"){if(window.alertexists!=="FALSE"){fsm=true;}}
if(typeof window.adtakeover!=='undefined'){for(var i=window.adrefreshslots.length-1;i>=0;i--){if(window.adrefreshslots[i].indexOf('topbanner')!=-1){window.adrefreshslots.splice(i,1);}else if(window.adrefreshslots[i].indexOf('bigbox')!=-1){window.adrefreshslots.splice(i,1);}}}
var _evt=evt.replace('maps/','');for(i=0;i<mapproducts.length;i++){if(_evt==mapproducts[i]){if(typeof window.placecodedataparam!=="undefined"||fsm){var mapviewclass=$("#map-view").attr("class");var expnd=false;if(mapviewclass){expnd=mapviewclass.indexOf("expanded")!=-1}
if(expnd||fsm){for(j=0;j<window.adrefreshslots.length;j++){if(window.adrefreshslots[j].indexOf(adproducts[i])!=-1&&window.adrefreshslots[j].indexOf(fsm?'fullscreen':'citypagemap')!=-1){var elm=document.getElementById(window.adrefreshslots[j]);if(window.maplayershown.indexOf(elm)!=-1){$(window.maplayershown).empty();googletag.pubads().refresh([window.adslots[window.adrefreshslots[j]]]);}
if(window.maplayershown.indexOf(elm)==-1){$(window.maplayershown).empty();googletag.display(window.adrefreshslots[j]);window.maplayershown.push(elm);}}}}else{for(j=0;j<window.adrefreshslots.length;j++){if(window.adrefreshslots[j].indexOf(adproducts[i])!=-1&&window.adrefreshslots[j].indexOf(fsm?'fullscreen':'citypagemap')!=-1){window.maplayertoshow=window.adrefreshslots[j];}}}}else{var elm=document.getElementById('div-gpt-ad-topbanner');if($.inArray(elm,window.maplayershown)){window.maplayershown.push(elm);}
if(typeof window.adtakeover=='undefined'){$("#div-gpt-ad-topbanner").empty();$("#div-gpt-ad-bigbox").empty();$("#div-gpt-ad-bigbox").hide();}
for(j=0;j<window.adrefreshslots.length;j++){$("#"+window.adrefreshslots[j]).empty();$("#"+window.adrefreshslots[j]).hide();}
var adslotstodisplay=new Array();for(j=0;j<window.adrefreshslots.length;j++){if(window.adrefreshslots[j].indexOf('maps_'+adproducts[i])!=-1){adslotstodisplay.push(window.adrefreshslots[j]);}}
var maplayershownupdated=false;var elm=document.getElementById(adslotstodisplay[1]);window.maplayershownslotname=adslotstodisplay[1];if(window.maplayershown.indexOf(elm)!=-1){for(j=0;j<adslotstodisplay.length;j++){window.adslots[adslotstodisplay[j]].setCategoryExclusion('_Run Only Above The Fold');}
googletag.pubads().refresh([window.adslots[adslotstodisplay[0]],window.adslots[adslotstodisplay[1]],window.adslots[adslotstodisplay[2]],window.adslots[adslotstodisplay[3]],window.adslots[adslotstodisplay[4]],window.adslots[adslotstodisplay[5]]]);}
if(window.maplayershown.indexOf(elm)==-1){for(j=0;j<adslotstodisplay.length;j++){googletag.display(adslotstodisplay[j]);if(!maplayershownupdated){window.maplayershown.push(elm);maplayershownupdated=true;}}}}}}},webtag_mapad:function(){var map,b=null;_parse=console.warn;var n="//maps.google.com/maps/api/js?v=3.14";var nInfo="//google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js";try{if(typeof window.google=='undefined'||typeof window.google.maps=='undefined'){if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("No Google Maps library available on page load so inserting the script to the page");}
if(window._config&&window._config.maps&&window._config.maps.apikey){n+=((n.indexOf('?')<0)?'?':'&')+'client='+window._config.maps.apikey;n+='&sensor='+(_config.platform!='web');n+="&callback=processDFP.webtag_mapad";if(typeof window._config!='undefined'&&typeof window._config.locale!='undefined'&&window._config.locale){n+='&channel='+window._config.locale+'_'+window._config.platform;if(window._config.lang){n+='&language='+window._config.lang;}}}
if(typeof window._config.map_lib_loading=='undefined'){if(typeof window.google=='undefined'||typeof window.google.maps=='undefined'){var gs=document.createElement('SCRIPT');gs.id="google-map-v31";gs.src=n;if(typeof window.google=='undefined'||typeof window.google.maps=='undefined'&&typeof window.google.maps.LatLng!='undefined'&&typeof window.google.maps.Map!='undefined'){document.getElementsByTagName('head')[0].appendChild(gs);window._config.map_lib_loading=true;}
if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info(gs);}}}else{if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Google Maps library loaded and its available to use");}
if(typeof window.google!='undefined'&&typeof window.google.maps!='undefined'&&typeof window.google.maps.LatLng!='undefined'&&typeof window.google.maps.Map!='undefined'){window.runAdCampaign();}else{window.pelmCustomAd.timerSet=setTimeout(function(){window.runAdCampaign();},500);window.pelmCustomAd.initialAdRun=true;}}}else{var chkMlLib=function(){if(typeof window.google!='undefined'&&typeof window.google.maps!='undefined'&&typeof window.google.maps.LatLng!='undefined'&&typeof window.google.maps.Map!='undefined'){window.runAdCampaign();}else{setTimeout(chkMlLib,100);}}
setTimeout(chkMlLib,100);}
if(window.pelmCustomAd.options.flag_markers_cluster){addClustering();if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Marker Cluster library is added to the page");}}}catch(err){if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.log(err);}}
window.runAdCampaign=function(){if(typeof window.google=='undefined'||typeof window.google.maps=='undefined'||typeof window.google.maps.LatLng=='undefined'||typeof window.google.maps.Map=='undefined'){return setTimeout(window.runAdCampaign,100);}
var infowindow;var myLatlng=new google.maps.LatLng(window.pelmCustomAd.uLat,window.pelmCustomAd.uLng);if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Current location Lat and lng:: "+window.pelmCustomAd.uLat,window.pelmCustomAd.uLng);}
if(typeof window.pelmCustomAd.timerSet!='boolean'){clearTimeout(window.pelmCustomAd.timerSet);window.pelmCustomAd.clearTimerSet=true;}
function renderMap(){var mapOptions={zoom:window.pelmCustomAd.options.map_zoom,mapTypeControl:false,panControl:false,zoomControl:true,zoomControlOptions:{position:google.maps.ControlPosition.LEFT_BOTTOM},streetViewControl:false,center:myLatlng}
map=new google.maps.Map(document.getElementById('div-gpt-ad-bigbox-maps_webtagging_ad'),mapOptions);window.pelmCustomAd._m=map;window.pelmCustomAd.initialLoad=0;loadCampaingnData(map);if(window.pelmCustomAd.options.flag_expandmap){var node=document.getElementById('div-gpt-ad-bigbox-maps_webtagging_ad')
var ne=document.createElement('div');ne.id='map-expand-options';ne.innerHTML='<div class="controls"><i class="icon-full-screen" id="expand" onclick=""></i><i id="reset" class="icon-exit-full-screen" onclick=""></i></div>';node.appendChild(ne);}}
var _getMapBounding=function(map){if(!b){return{x1:null,y1:null,x2:null,y2:null}}
return{x1:b.getSouthWest().lng(),y1:b.getNorthEast().lat(),x2:b.getNorthEast().lng(),y2:b.getSouthWest().lat()}}
function loadCampaingnData(map){if(b=map.getBounds()){var opts=_getMapBounding(map),du=document.location.origin;if(typeof du=='undefined'){du=window.location.protocol+"//"+window.location.hostname+(window.location.port?':'+window.location.port:'');}
if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Bounding box for the current  map window:: ");console.log(opts);}
if(window.pelmCustomAd.options.sample){__.a(du+"/api/maps/mapad_locations/{0}/{1}/{2}/{3}/{4}".format(240224559,opts.x1,opts.y1,opts.x2,opts.y2),setMarkers,_parse);if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Fetching the sample data with the parameters passed in the order of /CampaingID/X1/Y1/X2/Y2:: "+du+"/api/maps/mapad_locations/{0}/{1}/{2}/{3}/{4}".format(240224559,opts.x1,opts.y1,opts.x2,opts.y2));}}else{__.a("/api/maps/mapad_locations/{0}/{1}/{2}/{3}/{4}".format(window.pelmCustomAd.campainid,opts.x1,opts.y1,opts.x2,opts.y2),setMarkers,_parse);if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Fetching the data with the parameters passed in the order of /CampaingID/X1/Y1/X2/Y2:: "+du+"/api/maps/mapad_locations/{0}/{1}/{2}/{3}/{4}".format(window.pelmCustomAd.campainid,opts.x1,opts.y1,opts.x2,opts.y2));}}}else{setTimeout(function(){},100);}}
(function(){google.maps.Map.prototype.markers=new Array();google.maps.Map.prototype.addMarker=function(marker){this.markers[this.markers.length]=marker;};google.maps.Map.prototype.getMarkers=function(){return this.markers};google.maps.Map.prototype.clearMarkers=function(){if(infowindow){infowindow.close();}
for(var i=0;i<this.markers.length;i++){this.markers[i].set_map(null);}};})();function createMarker(info,latlng){var cs='<div class="popup-info">#logo-image#<p class="title">#title#</p><p>#desc#</p></div>';var pinImage={url:window.pelmCustomAd.options.marker_image,size:new google.maps.Size(32,32),origin:new google.maps.Point(0,0),anchor:new google.maps.Point(0,32)};var clickurl='';phoneno='';logourl='';if(window.pelmCustomAd.options.marker_image!=false){var marker=new google.maps.Marker({position:latlng,map:map,title:info.Name,zIndex:1,icon:pinImage});}else{var marker=new google.maps.Marker({position:latlng,map:map,title:info.Name,zIndex:1});}
google.maps.event.addListener(marker,"click",function(){if(infowindow){infowindow.close();}
if(typeof info!="undefined"&&typeof info.impressionUrl!="undefined"&&info.impressionUrl!=''){var img=new Image(1,1);img.src=info.impressionUrl;if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Conversion Tracking:: ");console.log(img);}}else{if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("There is no ImpressionUrl for this location:: ");}}
if(typeof info!="undefined"&&typeof info.LogoUrl!="undefined"&&info.LogoUrl!=''){logourl='<img class="tag-logo" src="'+info.LogoUrl+'" alt="'+info.Name+'" height="42" width="42"></img>';}
if(typeof info!="undefined"&&typeof info.clickUrl!="undefined"&&info.clickUrl!=''){clickurl='<i class="icon-link"></i><a href="'+info.clickUrl+'" target="_blank">WWW</a>';info.Name='<a href="'+info.clickUrl+'" target="_blank">'+info.Name+'</a>';}
if(typeof info!="undefined"&&typeof info.Phone!="undefined"&&info.Phone!=''){phoneno=info.Phone;}
cs=cs.replace('#logo-image#',logourl).replace('#title#',info.Name).replace('#desc#',info.Address+'<br/>'+info.City+', '+info.Province+' '+info.PostalCode+'<br/><span class="phone">'+phoneno+'</span><span class="www">'+clickurl+'</span>');infowindow=new google.maps.InfoWindow({content:cs});infowindow.open(map,marker);});return marker;}
function setMarkers(locations){var markers=[],b,mk;lc=Function('return ('+locations+')')();lc=lc.Locations;if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Total number of locations available within the given range:: "+lc.length);}
for(b in lc){lcc=lc[b].Coordinates;lccinfo=lc[b].LocationInfo;lccinfo.clickUrl=lc[b].ClickUrl;lccinfo.impressionUrl=lc[b].ImpressionUrl;var ll=new google.maps.LatLng(lcc.Latitude,lcc.Longitude);mk=createMarker(lccinfo,ll);map.addMarker(mk);if(window.pelmCustomAd.options.flag_markers_cluster){markers.push(mk);}}
if(window.pelmCustomAd.options.flag_markers_cluster){var mcOptions={gridSize:window.pelmCustomAd.options.markers_cluster.gridSize,maxZoom:window.pelmCustomAd.options.markers_cluster.maxZoom};var markerCluster=new MarkerClusterer(map,markers,mcOptions);if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Clustering of markers are processed by passing the below options to the library:: ");console.log(mcOptions);}}}
renderMap();if(window.pelmCustomAd.options.flag_expandmap){var actions={'expand':expandMap,'reset':reset};for(var act in actions){google.maps.event.addDomListener(document.getElementById(act),'click',actions[act]);}}
var tagElm=document.getElementById("div-gpt-ad-bigbox-maps_webtagging_ad");var mapExpand=false;mapReset=false;google.maps.event.addListener(map,'zoom_changed',function(){if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Maps bounding box after zoom::");console.info("Current Zoom is ::"+map.getZoom());if(b=map.getBounds()){console.log(_getMapBounding(map));}}});google.maps.event.addListener(map,'center_changed',function(){if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Maps bounding box after Pan::");if(b=map.getBounds()){console.log(_getMapBounding(map));}}});function expandMap(){tagElm.className='map-expand';mapExpand=true;var expandLatlng=new google.maps.LatLng(window.pelmCustomAd.uLat,window.pelmCustomAd.uLng);if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Map expand:: ");console.log("Map Center LatLong::"+expandLatlng);console.log("zoom::"+window.pelmCustomAd.options.expandmap.zoom);console.info("Maps bounding box before resize::");if(b=map.getBounds()){console.log(_getMapBounding(map));}}
google.maps.event.addListener(map,'bounds_changed',function(){if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Maps bounding box after resize::");if(b=map.getBounds()){console.log(_getMapBounding(map));}}
if(mapExpand){map.setCenter(expandLatlng);}
mapExpand=false;});map.setZoom(window.pelmCustomAd.options.expandmap.zoom);google.maps.event.trigger(map,'resize');}
function reset(){tagElm.className='map-reset';mapReset=true;var resetLatlng=new google.maps.LatLng(window.pelmCustomAd.uLat,window.pelmCustomAd.uLng);if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Reset to original size with the default values:: ");console.log("Map Center LatLong::"+resetLatlng);console.log("zoom::"+window.pelmCustomAd.options.map_zoom);console.info("Maps bounding box before reset ::");if(b=map.getBounds()){console.log(_getMapBounding(map));}}
google.maps.event.addListener(map,'bounds_changed',function(){if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Maps bounding box after reset::");if(b=map.getBounds()){console.log(_getMapBounding(map));}}
if(mapReset){map.setCenter(resetLatlng);}
mapReset=false;});map.setZoom(window.pelmCustomAd.options.map_zoom);google.maps.event.trigger(map,'resize');}
google.maps.event.addListener(map,'idle',function(){if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Load the data since map is in idle state::");}
window.pelmCustomAd.idleTimeout=window.setTimeout(function(){loadCampaingnData(map);window.pelmCustomAd.initialLoad+=1;},500);google.maps.event.addListenerOnce(map,'bounds_changed',function(){window.clearTimeout(window.pelmCustomAd.idleTimeout);});});}
String.prototype.format=function(){var a=arguments;return this.replace(/{(\d+)}/g,function(m,n){return typeof a[n]!='undefined'?a[n]:m;});};}};function contains(parent,descendant){return parent==descendant||Boolean(parent.compareDocumentPosition(descendant)&16);}
window.pelmCustomAd={companionadplayed:false,initialAdRun:false,recurringAdRun:false,timerSet:false,idleTimeout:false,clearTimerSet:false,options:{marker_image:false,map_zoom:8,flag_markers_cluster:false,markers_cluster:{gridSize:50,maxZoom:15},flag_expandmap:true,expandmap:{boundingbox:{x1:'',y1:'',x2:'',y2:''},zoom:8,},sample:false,debug:false}};window.runMapAd=function(campainid,options){if(typeof campainid!='undefined'&&campainid){window.pelmCustomAd.campainid=campainid;var tloc;if(typeof localStorage['lastKnownLocation']!='undefined'){tloc=JSON.parse(localStorage['lastKnownLocation']);}
if((typeof tloc!="undefined")&&(typeof tloc=="object")&&(typeof tloc.lat!="undefined")&&(typeof tloc.lng!="undefined")&&(typeof window._config.placecode=="undefined")){window.pelmCustomAd.uLat=tloc.lat;window.pelmCustomAd.uLng=tloc.lng;}else if((typeof window._user_config!="undefined")&&(typeof window._user_config=="object")&&(typeof window._user_config.lat!="undefined")&&(typeof window._user_config.lng!="undefined")){window.pelmCustomAd.uLat=window._user_config.lat;window.pelmCustomAd.uLng=window._user_config.lng;}else if((typeof window._config.lat!="undefined")&&(typeof window._config.lng!="undefined")){window.pelmCustomAd.uLat=window._config.lat;window.pelmCustomAd.uLng=window._config.lng;if(typeof window._config.placecode=="undefined"&&typeof options!='undefined'&&typeof options.last_fallback_lat!='undefined'&&typeof options.last_fallback_lng!='undefined'&&typeof options.last_fallback_zoom!='undefined'){window.pelmCustomAd.uLat=options.last_fallback_lat;window.pelmCustomAd.uLng=options.last_fallback_lng;options.map_zoom=options.last_fallback_zoom;}}
if(typeof options!='undefined'&&typeof options.map_zoom!='undefined'&&typeof options.expandmap=='undefined'){options.expandmap=window.pelmCustomAd.options.expandmap;options.expandmap.zoom=options.map_zoom-1;};for(var k in options){if(window.pelmCustomAd.options.hasOwnProperty(k)){window.pelmCustomAd.options[k]=options[k];}}
if(window.pelmCustomAd.options.debug&&typeof console!="undefined"&&console.log){console.info("Options passed:: ");console.log(options);console.info("Values are stored in global variable pelmCustomAd::");console.log(pelmCustomAd);}
if(window.pelmCustomAd.companionadplayed==false){document.getElementById("div-gpt-ad-bigbox-maps_webtagging_ad").className='ad-bigbox-map';processDFP.webtag_mapad();}
window.pelmCustomAd.companionadplayed=true;(function(){if(document.getElementById('div-gpt-ad-bigbox-maps_webtagging_ad').childNodes.length!=2&&!window.pelmCustomAd.clearTimerSet){window.pelmCustomAd.timerSet=setTimeout(function(){window.runAdCampaign();},500);window.pelmCustomAd.recurringAdRun=true;}})();}};function addClustering(){if(window.pelmCustomAd.options.flag_markers_cluster){function MarkerClusterer(map,opt_markers,opt_options){this.extend(MarkerClusterer,google.maps.OverlayView);this.map_=map;this.markers_=[];this.clusters_=[];this.sizes=[53,56,66,78,90];this.styles_=[];this.ready_=false;var options=opt_options||{};this.gridSize_=options['gridSize']||60;this.minClusterSize_=options['minimumClusterSize']||2;this.maxZoom_=options['maxZoom']||null;this.styles_=options['styles']||[];this.imagePath_=options['imagePath']||this.MARKER_CLUSTER_IMAGE_PATH_;this.imageExtension_=options['imageExtension']||this.MARKER_CLUSTER_IMAGE_EXTENSION_;this.zoomOnClick_=true;if(options['zoomOnClick']!=undefined){this.zoomOnClick_=options['zoomOnClick'];}
this.averageCenter_=false;if(options['averageCenter']!=undefined){this.averageCenter_=options['averageCenter'];}
this.setupStyles_();this.setMap(map);this.prevZoom_=this.map_.getZoom();var that=this;google.maps.event.addListener(this.map_,'zoom_changed',function(){var zoom=that.map_.getZoom();if(that.prevZoom_!=zoom){that.prevZoom_=zoom;that.resetViewport();}});google.maps.event.addListener(this.map_,'idle',function(){that.redraw();});if(opt_markers&&opt_markers.length){this.addMarkers(opt_markers,false);}}
MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_='https://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/'+'images/m';MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_EXTENSION_='png';MarkerClusterer.prototype.extend=function(obj1,obj2){return(function(object){for(var property in object.prototype){this.prototype[property]=object.prototype[property];}
return this;}).apply(obj1,[obj2]);};MarkerClusterer.prototype.onAdd=function(){this.setReady_(true);};MarkerClusterer.prototype.draw=function(){};MarkerClusterer.prototype.setupStyles_=function(){if(this.styles_.length){return;}
for(var i=0,size;size=this.sizes[i];i++){this.styles_.push({url:this.imagePath_+(i+1)+'.'+this.imageExtension_,height:size,width:size});}};MarkerClusterer.prototype.fitMapToMarkers=function(){var markers=this.getMarkers();var bounds=new google.maps.LatLngBounds();for(var i=0,marker;marker=markers[i];i++){bounds.extend(marker.getPosition());}
this.map_.fitBounds(bounds);};MarkerClusterer.prototype.setStyles=function(styles){this.styles_=styles;};MarkerClusterer.prototype.getStyles=function(){return this.styles_;};MarkerClusterer.prototype.isZoomOnClick=function(){return this.zoomOnClick_;};MarkerClusterer.prototype.isAverageCenter=function(){return this.averageCenter_;};MarkerClusterer.prototype.getMarkers=function(){return this.markers_;};MarkerClusterer.prototype.getTotalMarkers=function(){return this.markers_.length;};MarkerClusterer.prototype.setMaxZoom=function(maxZoom){this.maxZoom_=maxZoom;};MarkerClusterer.prototype.getMaxZoom=function(){return this.maxZoom_;};MarkerClusterer.prototype.calculator_=function(markers,numStyles){var index=0;var count=markers.length;var dv=count;while(dv!==0){dv=parseInt(dv/10,10);index++;}
index=Math.min(index,numStyles);return{text:count,index:index};};MarkerClusterer.prototype.setCalculator=function(calculator){this.calculator_=calculator;};MarkerClusterer.prototype.getCalculator=function(){return this.calculator_;};MarkerClusterer.prototype.addMarkers=function(markers,opt_nodraw){for(var i=0,marker;marker=markers[i];i++){this.pushMarkerTo_(marker);}
if(!opt_nodraw){this.redraw();}};MarkerClusterer.prototype.pushMarkerTo_=function(marker){marker.isAdded=false;if(marker['draggable']){var that=this;google.maps.event.addListener(marker,'dragend',function(){marker.isAdded=false;that.repaint();});}
this.markers_.push(marker);};MarkerClusterer.prototype.addMarker=function(marker,opt_nodraw){this.pushMarkerTo_(marker);if(!opt_nodraw){this.redraw();}};MarkerClusterer.prototype.removeMarker_=function(marker){var index=-1;if(this.markers_.indexOf){index=this.markers_.indexOf(marker);}else{for(var i=0,m;m=this.markers_[i];i++){if(m==marker){index=i;break;}}}
if(index==-1){return false;}
marker.setMap(null);this.markers_.splice(index,1);return true;};MarkerClusterer.prototype.removeMarker=function(marker,opt_nodraw){var removed=this.removeMarker_(marker);if(!opt_nodraw&&removed){this.resetViewport();this.redraw();return true;}else{return false;}};MarkerClusterer.prototype.removeMarkers=function(markers,opt_nodraw){var removed=false;for(var i=0,marker;marker=markers[i];i++){var r=this.removeMarker_(marker);removed=removed||r;}
if(!opt_nodraw&&removed){this.resetViewport();this.redraw();return true;}};MarkerClusterer.prototype.setReady_=function(ready){if(!this.ready_){this.ready_=ready;this.createClusters_();}};MarkerClusterer.prototype.getTotalClusters=function(){return this.clusters_.length;};MarkerClusterer.prototype.getMap=function(){return this.map_;};MarkerClusterer.prototype.setMap=function(map){this.map_=map;};MarkerClusterer.prototype.getGridSize=function(){return this.gridSize_;};MarkerClusterer.prototype.setGridSize=function(size){this.gridSize_=size;};MarkerClusterer.prototype.getMinClusterSize=function(){return this.minClusterSize_;};MarkerClusterer.prototype.setMinClusterSize=function(size){this.minClusterSize_=size;};MarkerClusterer.prototype.getExtendedBounds=function(bounds){var projection=this.getProjection();var tr=new google.maps.LatLng(bounds.getNorthEast().lat(),bounds.getNorthEast().lng());var bl=new google.maps.LatLng(bounds.getSouthWest().lat(),bounds.getSouthWest().lng());var trPix=projection.fromLatLngToDivPixel(tr);trPix.x+=this.gridSize_;trPix.y-=this.gridSize_;var blPix=projection.fromLatLngToDivPixel(bl);blPix.x-=this.gridSize_;blPix.y+=this.gridSize_;var ne=projection.fromDivPixelToLatLng(trPix);var sw=projection.fromDivPixelToLatLng(blPix);bounds.extend(ne);bounds.extend(sw);return bounds;};MarkerClusterer.prototype.isMarkerInBounds_=function(marker,bounds){return bounds.contains(marker.getPosition());};MarkerClusterer.prototype.clearMarkers=function(){this.resetViewport(true);this.markers_=[];};MarkerClusterer.prototype.resetViewport=function(opt_hide){for(var i=0,cluster;cluster=this.clusters_[i];i++){cluster.remove();}
for(var i=0,marker;marker=this.markers_[i];i++){marker.isAdded=false;if(opt_hide){marker.setMap(null);}}
this.clusters_=[];};MarkerClusterer.prototype.repaint=function(){var oldClusters=this.clusters_.slice();this.clusters_.length=0;this.resetViewport();this.redraw();window.setTimeout(function(){for(var i=0,cluster;cluster=oldClusters[i];i++){cluster.remove();}},0);};MarkerClusterer.prototype.redraw=function(){this.createClusters_();};MarkerClusterer.prototype.distanceBetweenPoints_=function(p1,p2){if(!p1||!p2){return 0;}
var R=6371;var dLat=(p2.lat()-p1.lat())*Math.PI/180;var dLon=(p2.lng()-p1.lng())*Math.PI/180;var a=Math.sin(dLat/2)*Math.sin(dLat/2)+
Math.cos(p1.lat()*Math.PI/180)*Math.cos(p2.lat()*Math.PI/180)*Math.sin(dLon/2)*Math.sin(dLon/2);var c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));var d=R*c;return d;};MarkerClusterer.prototype.addToClosestCluster_=function(marker){var distance=40000;var clusterToAddTo=null;var pos=marker.getPosition();for(var i=0,cluster;cluster=this.clusters_[i];i++){var center=cluster.getCenter();if(center){var d=this.distanceBetweenPoints_(center,marker.getPosition());if(d<distance){distance=d;clusterToAddTo=cluster;}}}
if(clusterToAddTo&&clusterToAddTo.isMarkerInClusterBounds(marker)){clusterToAddTo.addMarker(marker);}else{var cluster=new Cluster(this);cluster.addMarker(marker);this.clusters_.push(cluster);}};MarkerClusterer.prototype.createClusters_=function(){if(!this.ready_){return;}
var mapBounds=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast());var bounds=this.getExtendedBounds(mapBounds);for(var i=0,marker;marker=this.markers_[i];i++){if(!marker.isAdded&&this.isMarkerInBounds_(marker,bounds)){this.addToClosestCluster_(marker);}}};function Cluster(markerClusterer){this.markerClusterer_=markerClusterer;this.map_=markerClusterer.getMap();this.gridSize_=markerClusterer.getGridSize();this.minClusterSize_=markerClusterer.getMinClusterSize();this.averageCenter_=markerClusterer.isAverageCenter();this.center_=null;this.markers_=[];this.bounds_=null;this.clusterIcon_=new ClusterIcon(this,markerClusterer.getStyles(),markerClusterer.getGridSize());}
Cluster.prototype.isMarkerAlreadyAdded=function(marker){if(this.markers_.indexOf){return this.markers_.indexOf(marker)!=-1;}else{for(var i=0,m;m=this.markers_[i];i++){if(m==marker){return true;}}}
return false;};Cluster.prototype.addMarker=function(marker){if(this.isMarkerAlreadyAdded(marker)){return false;}
if(!this.center_){this.center_=marker.getPosition();this.calculateBounds_();}else{if(this.averageCenter_){var l=this.markers_.length+1;var lat=(this.center_.lat()*(l-1)+marker.getPosition().lat())/l;var lng=(this.center_.lng()*(l-1)+marker.getPosition().lng())/l;this.center_=new google.maps.LatLng(lat,lng);this.calculateBounds_();}}
marker.isAdded=true;this.markers_.push(marker);var len=this.markers_.length;if(len<this.minClusterSize_&&marker.getMap()!=this.map_){marker.setMap(this.map_);}
if(len==this.minClusterSize_){for(var i=0;i<len;i++){this.markers_[i].setMap(null);}}
if(len>=this.minClusterSize_){marker.setMap(null);}
this.updateIcon();return true;};Cluster.prototype.getMarkerClusterer=function(){return this.markerClusterer_;};Cluster.prototype.getBounds=function(){var bounds=new google.maps.LatLngBounds(this.center_,this.center_);var markers=this.getMarkers();for(var i=0,marker;marker=markers[i];i++){bounds.extend(marker.getPosition());}
return bounds;};Cluster.prototype.remove=function(){this.clusterIcon_.remove();this.markers_.length=0;delete this.markers_;};Cluster.prototype.getSize=function(){return this.markers_.length;};Cluster.prototype.getMarkers=function(){return this.markers_;};Cluster.prototype.getCenter=function(){return this.center_;};Cluster.prototype.calculateBounds_=function(){var bounds=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(bounds);};Cluster.prototype.isMarkerInClusterBounds=function(marker){return this.bounds_.contains(marker.getPosition());};Cluster.prototype.getMap=function(){return this.map_;};Cluster.prototype.updateIcon=function(){var zoom=this.map_.getZoom();var mz=this.markerClusterer_.getMaxZoom();if(mz&&zoom>mz){for(var i=0,marker;marker=this.markers_[i];i++){marker.setMap(this.map_);}
return;}
if(this.markers_.length<this.minClusterSize_){this.clusterIcon_.hide();return;}
var numStyles=this.markerClusterer_.getStyles().length;var sums=this.markerClusterer_.getCalculator()(this.markers_,numStyles);this.clusterIcon_.setCenter(this.center_);this.clusterIcon_.setSums(sums);this.clusterIcon_.show();};function ClusterIcon(cluster,styles,opt_padding){cluster.getMarkerClusterer().extend(ClusterIcon,google.maps.OverlayView);this.styles_=styles;this.padding_=opt_padding||0;this.cluster_=cluster;this.center_=null;this.map_=cluster.getMap();this.div_=null;this.sums_=null;this.visible_=false;this.setMap(this.map_);}
ClusterIcon.prototype.triggerClusterClick=function(event){var markerClusterer=this.cluster_.getMarkerClusterer();google.maps.event.trigger(markerClusterer,'clusterclick',this.cluster_,event);if(markerClusterer.isZoomOnClick()){this.map_.fitBounds(this.cluster_.getBounds());}};ClusterIcon.prototype.onAdd=function(){this.div_=document.createElement('DIV');if(this.visible_){var pos=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(pos);this.div_.innerHTML=this.sums_.text;}
var panes=this.getPanes();panes.overlayMouseTarget.appendChild(this.div_);var that=this;google.maps.event.addDomListener(this.div_,'click',function(event){that.triggerClusterClick(event);});};ClusterIcon.prototype.getPosFromLatLng_=function(latlng){var pos=this.getProjection().fromLatLngToDivPixel(latlng);if(typeof this.iconAnchor_==='object'&&this.iconAnchor_.length===2){pos.x-=this.iconAnchor_[0];pos.y-=this.iconAnchor_[1];}else{pos.x-=parseInt(this.width_/2,10);pos.y-=parseInt(this.height_/2,10);}
return pos;};ClusterIcon.prototype.draw=function(){if(this.visible_){var pos=this.getPosFromLatLng_(this.center_);this.div_.style.top=pos.y+'px';this.div_.style.left=pos.x+'px';}};ClusterIcon.prototype.hide=function(){if(this.div_){this.div_.style.display='none';}
this.visible_=false;};ClusterIcon.prototype.show=function(){if(this.div_){var pos=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(pos);this.div_.style.display='';}
this.visible_=true;};ClusterIcon.prototype.remove=function(){this.setMap(null);};ClusterIcon.prototype.onRemove=function(){if(this.div_&&this.div_.parentNode){this.hide();this.div_.parentNode.removeChild(this.div_);this.div_=null;}};ClusterIcon.prototype.setSums=function(sums){this.sums_=sums;this.text_=sums.text;this.index_=sums.index;if(this.div_){this.div_.innerHTML=sums.text;}
this.useStyle();};ClusterIcon.prototype.useStyle=function(){var index=Math.max(0,this.sums_.index-1);index=Math.min(this.styles_.length-1,index);var style=this.styles_[index];this.url_=style['url'];this.height_=style['height'];this.width_=style['width'];this.textColor_=style['textColor'];this.anchor_=style['anchor'];this.textSize_=style['textSize'];this.backgroundPosition_=style['backgroundPosition'];this.iconAnchor_=style['iconAnchor'];};ClusterIcon.prototype.setCenter=function(center){this.center_=center;};ClusterIcon.prototype.createCss=function(pos){var style=[];style.push('background-image:url('+this.url_+');');var backgroundPosition=this.backgroundPosition_?this.backgroundPosition_:'0 0';style.push('background-position:'+backgroundPosition+';');if(typeof this.anchor_==='object'){if(typeof this.anchor_[0]==='number'&&this.anchor_[0]>0&&this.anchor_[0]<this.height_){style.push('height:'+(this.height_-this.anchor_[0])+'px; padding-top:'+this.anchor_[0]+'px;');}else if(typeof this.anchor_[0]==='number'&&this.anchor_[0]<0&&-this.anchor_[0]<this.height_){style.push('height:'+this.height_+'px; line-height:'+(this.height_+this.anchor_[0])+'px;');}else{style.push('height:'+this.height_+'px; line-height:'+this.height_+'px;');}
if(typeof this.anchor_[1]==='number'&&this.anchor_[1]>0&&this.anchor_[1]<this.width_){style.push('width:'+(this.width_-this.anchor_[1])+'px; padding-left:'+this.anchor_[1]+'px;');}else{style.push('width:'+this.width_+'px; text-align:center;');}}else{style.push('height:'+this.height_+'px; line-height:'+
this.height_+'px; width:'+this.width_+'px; text-align:center;');}
var txtColor=this.textColor_?this.textColor_:'black';var txtSize=this.textSize_?this.textSize_:11;style.push('cursor:pointer; top:'+pos.y+'px; left:'+
pos.x+'px; color:'+txtColor+'; position:absolute; font-size:'+
txtSize+'px; font-family:Arial,sans-serif; font-weight:bold');return style.join('');};window['MarkerClusterer']=MarkerClusterer;MarkerClusterer.prototype['addMarker']=MarkerClusterer.prototype.addMarker;MarkerClusterer.prototype['addMarkers']=MarkerClusterer.prototype.addMarkers;MarkerClusterer.prototype['clearMarkers']=MarkerClusterer.prototype.clearMarkers;MarkerClusterer.prototype['fitMapToMarkers']=MarkerClusterer.prototype.fitMapToMarkers;MarkerClusterer.prototype['getCalculator']=MarkerClusterer.prototype.getCalculator;MarkerClusterer.prototype['getGridSize']=MarkerClusterer.prototype.getGridSize;MarkerClusterer.prototype['getExtendedBounds']=MarkerClusterer.prototype.getExtendedBounds;MarkerClusterer.prototype['getMap']=MarkerClusterer.prototype.getMap;MarkerClusterer.prototype['getMarkers']=MarkerClusterer.prototype.getMarkers;MarkerClusterer.prototype['getMaxZoom']=MarkerClusterer.prototype.getMaxZoom;MarkerClusterer.prototype['getStyles']=MarkerClusterer.prototype.getStyles;MarkerClusterer.prototype['getTotalClusters']=MarkerClusterer.prototype.getTotalClusters;MarkerClusterer.prototype['getTotalMarkers']=MarkerClusterer.prototype.getTotalMarkers;MarkerClusterer.prototype['redraw']=MarkerClusterer.prototype.redraw;MarkerClusterer.prototype['removeMarker']=MarkerClusterer.prototype.removeMarker;MarkerClusterer.prototype['removeMarkers']=MarkerClusterer.prototype.removeMarkers;MarkerClusterer.prototype['resetViewport']=MarkerClusterer.prototype.resetViewport;MarkerClusterer.prototype['repaint']=MarkerClusterer.prototype.repaint;MarkerClusterer.prototype['setCalculator']=MarkerClusterer.prototype.setCalculator;MarkerClusterer.prototype['setGridSize']=MarkerClusterer.prototype.setGridSize;MarkerClusterer.prototype['setMaxZoom']=MarkerClusterer.prototype.setMaxZoom;MarkerClusterer.prototype['onAdd']=MarkerClusterer.prototype.onAdd;MarkerClusterer.prototype['draw']=MarkerClusterer.prototype.draw;Cluster.prototype['getCenter']=Cluster.prototype.getCenter;Cluster.prototype['getSize']=Cluster.prototype.getSize;Cluster.prototype['getMarkers']=Cluster.prototype.getMarkers;ClusterIcon.prototype['onAdd']=ClusterIcon.prototype.onAdd;ClusterIcon.prototype['draw']=ClusterIcon.prototype.draw;ClusterIcon.prototype['onRemove']=ClusterIcon.prototype.onRemove;}};