//Copyright © [Year(s)] Nokia Corporation and/or its subsidiary(-ies).

Fp.PremiumContent={providers:null,selectedIndex:-1,elements:[],init:function(){if(Fp.POI&&(Fp.POI.ownerContent||Fp.POI.premiumContent)){this.providers=Fp.POI.premiumContent;if(Fp.POI.ownerContent){if(this.providers){this.providers.unshift(Fp.POI.ownerContent);}else{this.providers=[Fp.POI.ownerContent];}}this.selectedIndex=-1;this.generatePList();this.setupEvents();}},setupEvents:function(){var a=this;new Fp.Utils.addTapEvent({element:Fp.byId("openPremium"),onEvent:function(){a.onDetailsClick.call(a);}});Fp.addListener("onResize",this.fillShortDescription,this);},onProviderClick:function(c){for(var b=0,a=this.elements.length;b<a;b++){this.elements[b].className="";}c.className="active";this.fillProviderContent(parseInt(c.getAttribute("name"),10));if(Fp.Tracking){Fp.Tracking.track("otherProvider");}},getTimezone:function(b){b=b||new Date();var e=new Date().getTimezoneOffset(),d=e<0?"p":"m",c=Math.abs(Math.floor(e/60)),a=e%60;if(c<10){c="0"+c;}if(a<10){a="0"+a;}return d+c+a;},onDetailsClick:function(){var d=this.providers[this.selectedIndex];if(Fp.OwnerContent.isProviderPrimePlace(d)){Fp.Pages.open({name:Fp.Pages.PAGE.OWNER_CONTENT,fromHistory:false});}else{var b=d.provider.toUpperCase();if(!Fp.Settings.premiumServices[b]){return;}var a=Fp.Settings.premiumURL+"?"+Fp.Settings.premiumServices[b],c=Fp.POI.language;a+="&geox="+Fp.POI.latitude;a+="&geoy="+Fp.POI.longitude;a+="&name="+encodeURIComponent(Fp.POI.name);a+="&language="+Fp.POI.language.substr(0,5);a+="&countrycode="+Fp.POI.address.countryCode.toLowerCase();a+="&metric="+(Fp.POI.distance.metric?1:0);a+="&uuid="+Fp.uuid;a+="&id="+Fp.POI.placeId;a+="&width="+window.screen.width;a+="&height="+window.screen.height;a+="&mapsClient=true&entryPoint=2";Fp.Pages.showPage({name:Fp.Pages.PAGE.PREMIUM_DETAIL,url:a});}if(Fp.Tracking){Fp.Tracking.track("moreInformation",b);}if(Fp.OwnerContent){Fp.OwnerContent.fillThumbnails();}},generatePList:function(){var c=this,f=Fp.byId("provider-list"),d=this.providers.length,e,b;f.innerHTML="";for(e=0,b=this.providers.length;e<b;e++){var g=document.createElement("li"),a=document.createElement("span");a.className=this.providers[e].className||this.providers[e].provider.toUpperCase().substring(0,4);g.appendChild(a);g.onmousedown=function(h){c.onProviderClick.call(c,h.currentTarget);};g.setAttribute("name",e);f.appendChild(g);this.elements[e]=g;}this.elements[0].className="active";this.fillProviderContent(0);},fillProviderContent:function(a){if(this.selectedIndex==a){return;}this.selectedIndex=a;Fp.byId("short-description-header").innerHTML=this.providers[this.selectedIndex].providerDisplayName||"";this.fillShortDescription();},fillShortDescription:function(){Fp.Utils.addTruncatedString({element:Fp.byId("short-description-content"),text:this.providers[this.selectedIndex].description||""});}};