(function(){var t=nspace("kidscount.nav.fn");t.takeOne=function(n){return _.isArray(n)?_.first(n):_.isObject(n)?_.first(_.values(n)):n},t.take=function(n,t){var i=t?t.count||1:1;return _.isArray(n)?_.first(n,i):_.isObject(n)?_.first(_.values(n),i):_.isUndefined(n)?[]:[n]},t.takeFromEach=function(n,t){var i=t?t.count||1:1,r=_.filter(_.values(n),function(n){return!_.isFunction(n)}),u=_.reduce(r,function(n,t){return _.isArray(t)&&n},!0);if(!u)throw"Non-array values were found!";return _.map(n,function(n){return _.isArray(n)?_.first(n,i):n})},t.expandSelection=function(n,t,i){var f,h=t?t.count||1:1,c=h%2==0,e=i.get(t.allSelections),r=c?h/2:(h-1)/2,l=c?h/2:(h-1)/2,o,s,u;return(f=_.isArray(n)?n:[n],f.length>1)?f:_.isUndefined(e)?(console.log("unable to find property ["+t.allSelections+"] in model: \n\r"+JSON.stringify(i.toJSON())),f):(u=e.indexOf(f[0]),o=u-r,s=u+l+(c?0:1),o<0&&(o=0,l+=r-u+(c?0:1),s=u+l,r=0),s>e.length&&(r=r+(s-e.length)+(c?0:1),o=u-r<0?0:u-r,s=e.length-1),e.slice(o,s+1))},t.serializeAsCsv=function(n){return _.isArray(n)?n.join(","):n},t.toArray=function(n){return[n]},t.sort=function(n){var i=null;return(_.isArray(n)?i=_.clone(n):_.isObject(n)&&(i=_.values(n)),!_.isArray(i))?n:(i.sort(function(n,t){return _.isNumber(n)&&_._isNumber(t)?parseInt(n)-parseInt(t):n-t}),i)},t.settings={fallback:{fallback:{isCompared:{destination:"isCompared"},allTimeFrameIds:{destination:"allTimeFrameIds"},allCharacteristicIds:{destination:"allCharacteristicIds"},allDataTypeIds:{destination:"allDataTypeIds"},loct:{destination:"locationTypeId"},loc:{destination:"locationIds"},tf:{destination:"timeFrameIds"},ch:{destination:"characteristicIds"},fmt:{destination:"dataTypeIds",handlers:[{handle:t.toArray}]}},detailed:{currentSection:{value:"detailed"},tf:{destination:"timeFrameIds",handlers:[{handler:t.take,options:{count:5}}]}},ranking:{currentSection:{value:"ranking"}},map:{loc:{destination:"locationIds",value:[]},tf:{destination:"timeFrameId",handlers:[{handle:t.takeOne}]},ch:{destination:"characteristicIds",handlers:[{handle:t.takeFromEach}],options:{count:1}},fmt:{destination:"dataTypeId",handlers:[{handle:t.takeOne}]},activeColorPalette:{value:"any"}},line:{loc:{destination:"locationIds",handlers:[{handle:t.sort},{handle:t.take,options:{count:7}}]},tf:{destination:"timeFrameIds",handlers:[{handle:t.expandSelection,options:{count:10,allSelections:"allTimeFrameIds"}},{handle:t.toArray}]},timeFrameDirection:{value:"asc"},fmt:{destination:"dataTypeId",handlers:[{handle:t.takeOne}]}},bar:{loc:{destination:"locationIds",handlers:[{handle:t.sort},{handle:t.take,options:{count:5}}]},tf:{destination:"timeFrameId",handlers:[{handle:t.takeOne}]},fmt:{destination:"dataTypeId",handlers:[{handle:t.takeOne}]}}},detailed:{map:{},line:{},bar:{}},ranking:{},map:{detailed:{},line:{},bar:{}},line:{detailed:{},map:{},bar:{}},bar:{detailed:{},map:{},line:{}}}})(jQuery),function(n){var i=nspace("kidscount.nav"),r=nspace("kidscount");i.IntervizTransitionHandler=function(n){this.settings=n||i.fn.settings},i.IntervizTransitionHandler.prototype.handle=function(t,i,u){var f,e,o,s;return t==i?u:(f=n.extend(!0,{},this.settings.fallback,this.settings[t]),e=n.extend(!0,{},f.fallback,f[i]),o=new r.routes.ModelMapper(e),s=o.map(u))}}(jQuery,_),function(n){var i=nspace("kidscount.nav"),t=nspace("kidscount");i.VisualizationTab=Backbone.View.extend({initialize:function(n){var r=this;if(!n.vizType)throw"vizType not defined!";_.bindAll(this),r.vizType=n.vizType,r.serializer=n.serializer||new t.routes.RouteSerializer,r.transitionHandler=n.transitionHandler||new i.IntervizTransitionHandler,n.getVizType&&(r.getVizType=n.getVizType),this.persist=new t.routes.ModelPersistence(this.model),this.normalizer=new t.routes.ModelNormalizer(this.persist),this.propertyNames=t.routes.fn.getAllRouteProperties();this.model.on("user:updated",this.updatePersistence);this.model.on("hydration:complete",this.hydrateSelections)},updateLink:function(t){var i=this,r=this.$el||(this.$el=n(this.el));r.is("a")||(r=r.find("a")),r.prop("href",function(){var u=n(this),e=u.prop("origin"),r=u.prop("pathname"),o=u.prop("search"),f,c=i.normalizer.getSelections(t),s=i.getVizType(u),h;return h=i.transitionHandler.handle(i.vizType,s,c.clone()),f=i.serializer.serialize(s,h),e?e+r+o+"#"+f:(r=r&&r.indexOf("/")==0?r:"/"+r,r+o+"#"+f)})},getVizType:function(n){return n.data("viztype")},hydrateSelections:function(){var n=this.persist.getSelections();_.isUndefined(n)&&(n=this.updatePersistence()),this.updateLink(n);this.model.on("persistence:updated",this.updateLink)},updatePersistence:function(){return this.normalizer.setSelections(this.model)}})}(jQuery,Backbone)