//Copyright © [Year(s)] Nokia Corporation and/or its subsidiary(-ies).
Fp.Ads={lpaAd:null,server:Fp.Settings.adsUrl,adPageUrl:null,adEle:null,moduleEle:null,data:{},isAd:false,modulesNameDefault:["PremiumContent","Reviews","Recommendations"],displayAd:true,isAdClicked:false,beaconTimeout:false,init:function(){this.adEle=document.getElementById("adEle");this.moduleEle=document.getElementById("module");new Fp.Utils.Events.addTapEvent({element:this.adEle,onEvent:Fp.Utils.bind(this.openAdPage,this)});this.advData={server:this.server,affiliateRef:Fp.Settings.adsAffiliateRef,initParams:{language:Fp.Lang.language,mapsClient:true,ver:Fp.Settings.DCver}};this.advData.url=this.advData.server+"?acver=web-S60-1.0&aref="+this.advData.affiliateRef+this.addParams(this.advData.initParams);},addParams:function(c){var a="";for(var b in c){if(c.hasOwnProperty(b)){a+="&"+b+"="+encodeURIComponent(c[b]);}}return a;},getNewAdd:function(b){this.clearAdEle();if(b&&true==b.isFirstData&&b.isOnline===1){this.adPageUrl=null;this.isAd=false;if(Fp.POI.latitude&&Fp.POI.longitude){var a={uuid:Fp.uuid,mapsVersion:(Fp.openData.mapsversion)?Fp.openData.mapsversion:"",mcc:(Fp.openData.mcc)?Fp.openData.mcc:"",mnc:(Fp.openData.mnc)?Fp.openData.mnc:"",cmcc:(Fp.openData.cmcc)?Fp.openData.cmcc:"",cmnc:(Fp.openData.cmnc)?Fp.openData.cmnc:"",metric:Fp.POI.distance.metric,rnd:Math.random(),lat:Fp.POI.latitude,lon:Fp.POI.longitude,keywords:""};if(Fp.POI.placeId){a.ppid=Fp.POI.placeId;}setTimeout(function(){var c=new Fp.Ajax.Request({url:Fp.Ads.advData.url+Fp.Ads.addParams(a),exresp:Fp.Ajax.ExResponse.JSON,method:"GET",timeout:5,lang:Fp.Lang.language,onSuccess:function(d,e){Fp.Ads.setUpAds(e);},onFailure:function(){Fp.Ads.setUpAds();},onTimeout:function(){Fp.Ads.setUpAds();}});c.send();},1);}}else{this.clearAdEle();}},clearAdEle:function(){this.adEle.innerHTML="";},toggleAdd:function(a){if(this.isAd===true&&this.displayAd===true&&(this.checkModule()||Fp.POI.isPlace!==true)&&Fp.POI.online){this.showAd();}else{this.hideAd();}},checkModule:function(){var a=Fp.Modules.Manager.loadedModules[Fp.Modules.Manager.vars.currentModule];if(a&&a.id){return this.modulesNameDefault.indexOf(a.id)!=-1?true:false;}return false;},hideAd:function(){Fp.Utils.removeClass(this.adEle,"show");Fp.Utils.addClass(this.adEle,"hide");Fp.Utils.removeClass(this.moduleEle,"ads");},showAd:function(){if(!this.adEle.innerHTML){this.adEle.innerHTML=this.data.markup;}Fp.Utils.removeClass(this.adEle,"hide");Fp.Utils.addClass(this.adEle,"show");Fp.Utils.addClass(this.moduleEle,"ads");},setUpAds:function(a){if(a&&a.markup){this.data=a;this.isAd=true;this.toggleAdd();return true;}else{if(a&&a.empty){this.addBeacon(a.empty);}}return false;},addBeacon:function(a,b){if(a){var c=document.createElement("img");c.src=a+"&rnd="+Math.random();c.style.display="none";if(b){c.onload=b;}document.body.appendChild(c);}},openAdPage:function(){if(this.isAdClicked){return false;}this.isAdClicked=true;if(this.data.actionUrl||this.data.click){if(this.data.actionUrl){this.addBeacon(this.data.actionUrl,Fp.Utils.bind(this.openDetails,this));}this.addBeacon(this.data.click);this.beaconTimeout=setTimeout(function(){this.openDetails();},2000);}else{this.openDetails();}},openDetails:function(){clearTimeout(this.beaconTimeout);this.isAdClicked=false;Fp.Utils.Iframe.open({url:this.data.detailsUrl});},setAdVisibility:function(a){this.displayAd=a;if(this.isAd===true&&this.checkModule()){if(this.displayAd===true){this.showAd();}else{this.hideAd();}}}};