var siteApp=angular.module("site",["ngRoute","publicationServices","passwordServices","disqusServices","ihpServices","publicationControllers","passwordControllers","ihpControllers","rssControllers"]),publicationServices,passwordServices,disqusServices,ihpServices,publicationControllers,passwordControllers,ihpControllers,rssControllers;siteApp.directive("checkboxRepeat",function(){return function(n,t){n.$last&&t.ready(function(){$("#"+t.parent()[0].id).foundation("forms")})}});siteApp.directive("selectRepeat",function(){return function(n,t,i){n.$last&&t.ready(function(){Foundation.libs.forms.refresh_custom_select($("select#"+i.selectRepeat),!0)})}});siteApp.directive("customCheck",function(){return{restrict:"A",link:function(n,t){$(t).bind("click",function(){n.ngModel=!n.ngModel;n.$apply()})}}});siteApp.config(["$routeProvider",function(n){n.when("/forgot-password",{templateUrl:"/account/forgot-password?view=modal",controller:"PasswordCtrl"}).when("/barchart/:ch/:loc/:sortch/:so",{templateUrl:"/theme/cwf/templates/datacenter/ihp/barchart.html",controller:"IhpChartController",action:"barchart"}).when("/datatable/:ch/:loc/:sortch/:so",{templateUrl:"/theme/cwf/templates/datacenter/ihp/datatable.html",controller:"IhpChartController",action:"datatable"})}]);siteApp.run(["$rootScope","$location",function(n,t){n.location=t}]);publicationServices=angular.module("publicationServices",["ngResource"]);publicationServices.factory("Publications",["$resource",function(n){return n("/api/search",{},{query:{method:"GET",params:{componentId:"@componentId",pageId:"@pageId",count:"@count",skip:"@skip",sort:"@sort"},isArray:!0},count:{method:"GET",params:{componentId:"@componentId",pageId:"@pageId"},isArray:!1}})}]);passwordServices=angular.module("passwordServices",["ngResource"]);passwordServices.factory("SendPassword",["$resource",function(n){return n("/api/send",{},{send:{method:"POST",params:{forgotEmail:"@email"}}})}]);disqusServices=angular.module("disqusServices",["ngResource"]);disqusServices.factory("Comments",["$resource",function(n){return n("/api/disqus",{},{query:{method:"GET",params:{thread:"@thread"},isArray:!0}})}]);ihpServices=angular.module("ihpServices",["ngResource"]);ihpServices.factory("IhpDatacenter",["$resource",function(n){return n("/api/datacenter/ihp",{},{getIndicators:{method:"GET",params:{category:"@category"},isArray:!0},getCharacteristics:{method:"GET",params:{method:"characteristics",category:"@category",indicator:"@indicator"},isArray:!0},getCountries:{method:"GET",params:{method:"countries",category:"@category",indicator:"@indicator"},isArray:!0},getData:{method:"GET",params:{method:"@method",ind:"@ind",loc:"@loc",ch:"@ch",sortch:"@sortch",so:"@so"}}})}]);ihpServices.factory("IhpUtility",function(){return{urlParamToArray:function(n){return n.split(",")},arrayToUrlParam:function(n){for(var i="",t=0;t<n.length;t++)t>0&&(i+=","),i+=n[t];return i}}});publicationControllers=angular.module("publicationControllers",[]);publicationControllers.controller("PublicationsCtrl",["$scope","$http","Publications","Comments",function(n,t,i,r){n.initialize=function(){n.listItems=[];n.getCount()};n.getPublications=function(){var t=i.query({componentId:n.componentId,pageId:n.pageId,count:n.count,skip:n.skip,sort:n.sort},function(){t.forEach(function(t){n.listItems.push(t)});n.getComments(t);n.skip+=n.count;n.count=10;n.left=u()})};n.getComments=function(t){var i=[];t.forEach(function(n){i.push("http://"+location.hostname+n.ListUrl)});r.query({thread:i},function(i){var u=n.skip-3,f,r;for(f in i)for(r=0;r<t.length;r++)n.listItems[u+parseInt(r)]!=null&&"http://"+location.hostname+n.listItems[u+parseInt(r)].ListUrl==i[f].Key&&(n.listItems[u+parseInt(r)].Comments=i[f].Value)})};n.getCount=function(){t.get("/api/search?componentId="+n.componentId+"&pageId="+n.pageId).success(function(t){n.total=t;n.getPublications()})};var u=function(){var t=n.total-n.skip;return t>n.count?n.count:t};n.$watch("componentId",function(){n.componentId&&n.initialize()})}]);passwordControllers=angular.module("passwordControllers",[]);passwordControllers.controller("PasswordCtrl",["$scope","SendPassword",function(n,t){n.send=function(){var i=t.send({email:n.email},function(){n.showThanks=i.Success;n.showError=!i.Success;i.Success&&setEvent("event9")})}}]);ihpControllers=angular.module("ihpControllers",[]);ihpControllers.controller("IhpController",["$scope","$route","$routeParams","$timeout","IhpDatacenter","IhpUtility",function(n,t,i,r,u,f){var e=!0;n.dataFormat="barchart";n.sortCharacteristic="0";n.sortOrder="Ascending";n.categoryChanged=function(){n.indicator="";n.indicators=u.getIndicators({category:n.category},function(){n.$broadcast("indicatorsChanged")})};n.indicatorChanged=function(){n.updateCharsAndLocs(null,null)};n.updateCharsAndLocs=function(t,i){n.characteristics=u.getCharacteristics({category:n.category,indicator:n.indicator},function(){var r,f,i,u;if(t!=null){for(r=0;r<t.length;r++)for(f=t[r],i=0;i<n.characteristics.length;i++)if(n.characteristics[i].Key==f){n.characteristics[i].checked=!0;continue}}else for(u=0;u<n.characteristics.length;u++)n.characteristics[u].checked=!0});n.countries=u.getCountries({category:n.category,indicator:n.indicator},function(){var r,f,t,u;if(i!=null){for(r=0;r<i.length;r++)for(f=i[r],t=0;t<n.countries.length;t++)if(n.countries[t].Key==f){n.countries[t].checked=!0;continue}}else for(u=0;u<n.countries.length;u++)n.countries[u].checked=!0})};n.getIdArray=function(n){var i,t;if(n){for(i=[],t=0;t<n.length;t++)n[t].checked&&i.push(n[t].Key);return i}};n.checkModelUpdate=function(n){r(function(){n.checked=!n.checked})};n.$on("$routeChangeSuccess",function(t,r){n.dataFormat=r.action||"barchart";var e=f.urlParamToArray(i.loc||""),o=f.urlParamToArray(i.ch||"");n.sortCharacteristic=i.sortch||"0";n.sortOrder=i.so||"Ascending";n.downloadParams="ind="+n.ind+"&loc="+f.arrayToUrlParam(e)+"&ch="+f.arrayToUrlParam(o)+"&sortch="+n.sortCharacteristic+"&so="+n.sortOrder;n.indicators=u.getIndicators({category:n.category});n.updateCharsAndLocs(o,e)});n.generateUrl=function(t){document.location=t+"?ind="+n.indicator+"&ch="+f.arrayToUrlParam(n.getIdArray(n.characteristics))+"#/"+n.dataFormat+"/"+f.arrayToUrlParam(n.getIdArray(n.characteristics))+"/"+f.arrayToUrlParam(n.getIdArray(n.countries))+"/"+n.sortCharacteristic+"/"+n.sortOrder};n.$watch("category",function(){r(function(){Foundation.libs.forms.refresh_custom_select($("select#category"),!0)})});n.$watchCollection("[dataFormat, sortCharacteristic, sortOrder]",function(){e&&r(function(){Foundation.libs.forms.refresh_custom_select($("select#category"),!0);Foundation.libs.forms.refresh_custom_select($("select#sortorder"),!0);Foundation.libs.forms.refresh_custom_select($("select#sortby"),!0)});!e&&n.characteristics!=null&&n.characteristics.length&&n.countries!=null&&n.characteristics.length&&n.location.url("/"+n.dataFormat+"/"+f.arrayToUrlParam(n.getIdArray(n.characteristics))+"/"+f.arrayToUrlParam(n.getIdArray(n.countries))+"/"+n.sortCharacteristic+"/"+n.sortOrder);e=!1})}]);ihpControllers.controller("IhpChartController",["$scope","$route","$routeParams","IhpDatacenter","IhpUtility",function(n,t,i,r,u){if(n.setLeft=function(n){return{left:n+"%"}},n.setWidth=function(n){return{width:n+"%"}},n.removeLocation=function(t){var i=n.locations.indexOf(""+t);i>-1&&(n.locations.splice(i,1),n.location.url("/"+n.dataFormat+"/"+u.arrayToUrlParam(n.characteristics)+"/"+u.arrayToUrlParam(n.locations)+"/"+n.sortCharacteristic+"/"+n.sortOrder))},n.ind!=undefined){n.dataFormat=t.current.action||"barchart";n.locations=u.urlParamToArray(i.loc||"");n.characteristics=u.urlParamToArray(i.ch||"");n.sortCharacteristic=i.sortch||"0";n.sortOrder=i.so||"Ascending";var f=r.getData({method:n.dataFormat,ind:n.ind,loc:n.locations,ch:n.characteristics,sortch:n.sortCharacteristic,so:n.sortOrder},function(){n.legendKeys=f.LegendLabels;n.scale=f.Scale;n.countries=f.Locations})}}]);rssControllers=angular.module("rssControllers",[]);rssControllers.controller("RssController",["$scope",function(n){n.topics=[];n.addRemoveTopic=function(t,i){for(var u=-1,r=0;r<n.topics.length;r++)if(n.topics[r].id==t){u=r;continue}u<0?n.topics.push({id:t,title:i}):n.topics.splice(u,1)};n.createFeed=function(t){for(var r=t+"?topics=",i=0;i<n.topics.length;i++)r+=i==0?"":"|",r+=n.topics[i].id;window.open(r,"_blank")}}])