(function(){var n=nspace("kidscount.nav.fn");n.takeOne=function(n,t,i,r){var u=t&&t.getDefault?t.getDefault(r):null;return _.isArray(n)?u&&_.contains(n,u)?u:_.first(n):_.isObject(n)?u&&_.contains(_.values(n),u)?u:_.first(_.values(n)):n},n.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]},n.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})},n.expandSelection=function(n,t,i){var o,s=t?t.count||1:1,h=s%2==0,f=i.get(t.allSelections),r=h?s/2:(s-1)/2,l=h?s/2:(s-1)/2,c,e,u;return(o=_.isArray(n)?n:[n],o.length>1)?o:_.isUndefined(f)?(console.log("unable to find property ["+t.allSelections+"] in model: \n\r"+JSON.stringify(i.toJSON())),o):(u=f.indexOf(o[0]),c=u-r,e=u+l+(h?0:1),c<0&&(c=0,l+=r-u+(h?0:1),e=u+l,r=0),e>f.length&&(r=r+(e-f.length)+(h?0:1),c=u-r<0?0:u-r,e=f.length-1),f.slice(c,e+1))},n.serializeAsCsv=function(n){return _.isArray(n)?n.join(","):n},n.toArray=function(n){return[n]},n.sort=function(n){var t=null;return(_.isArray(n)?t=_.clone(n):_.isObject(n)&&(t=_.values(n)),!_.isArray(t))?n:(t.sort(function(n,t){return _.isNumber(n)&&_._isNumber(t)?parseInt(n)-parseInt(t):n-t}),t)},n.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:n.toArray}]}},detailed:{currentSection:{value:"detailed"},tf:{destination:"timeFrameIds",handlers:[{handler:n.take,options:{count:5}}]}},ranking:{currentSection:{value:"ranking"}},map:{loc:{destination:"locationIds",value:[]},tf:{destination:"timeFrameId",handlers:[{handle:n.takeOne}]},ch:{destination:"characteristicIds",handlers:[{handle:n.takeFromEach}],options:{count:1}},fmt:{destination:"dataTypeId",handlers:[{handle:n.takeOne,options:{getDefault:function(n){return n.get("defaultFmt")}}}]},activeColorPalette:{value:"any"}},line:{loc:{destination:"locationIds",handlers:[{handle:n.sort},{handle:n.take,options:{count:7}}]},tf:{destination:"timeFrameIds",handlers:[{handle:n.expandSelection,options:{count:10,allSelections:"allTimeFrameIds"}},{handle:n.toArray}]},timeFrameDirection:{value:"asc"},fmt:{destination:"dataTypeId",handlers:[{handle:n.takeOne,options:{getDefault:function(n){return n.get("defaultFmt")}}}]}},bar:{loc:{destination:"locationIds",handlers:[{handle:n.sort},{handle:n.take,options:{count:5}}]},tf:{destination:"timeFrameId",handlers:[{handle:n.takeOne}]},fmt:{destination:"dataTypeId",handlers:[{handle:n.takeOne,options:{getDefault:function(n){return n.get("defaultFmt")}}}]}}},detailed:{map:{},line:{},bar:{}},ranking:{},map:{detailed:{},line:{},bar:{}},line:{detailed:{},map:{},bar:{}},bar:{detailed:{},map:{},line:{}}}})(jQuery),function(n){var t=nspace("kidscount.nav"),i=nspace("kidscount");t.IntervizTransitionHandler=function(n){this.settings=n||t.fn.settings},t.IntervizTransitionHandler.prototype.handle=function(t,r,u,f){var e,o,s;return t==r?u:(e=n.extend(!0,{},this.settings.fallback,this.settings[t]),o=n.extend(!0,{},e.fallback,e[r]),s=new i.routes.ModelMapper(o,f),s.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(),i.model),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)