var arrestPlacementRates=function(n,t){var r={},u={},f=[],i={init:function(u){r=n.extend(!0,{stateName:"",url:"/"},u);i.setupCharts();var f=new t.dataLoader({url:r.url,useLocal:!1,events:{error:function(n){window.console&&console.error("State arrest placement rates data loader error: "+n.join("; "))},loaded:i.onDataLoaded},retry:{enabled:!0,timeout:7e3}});f.load()},onDataLoaded:function(t){u=t.Model;i.initCharts();n(".apr-insufficient-data").qtip({content:{text:'<div class="tooltip">'+setup.text.state.arrestRatesNoData+"<\/div>"},show:{solo:!0},hide:{event:"unfocus",inactive:1250}})},setupCharts:function(){n(".ap-chart").each(function(){f.push(new e(n(this)))})},initCharts:function(){f.foreach(function(n){var i=u.NationalRates.findAll(function(t){return t.statusId===n.statusId&&t.offenseId===n.offenseId}).orderBy({del:function(n){return n.y}}),t;n.fnSetDataUS(i);t=u.StateRates.findAll(function(t){return t.statusId===n.statusId&&t.offenseId===n.offenseId}).orderBy({del:function(n){return n.y}});n.fnSetDataState(t);n.fnInitSparkline()})}},e=function(){return function(t){var f=parseInt(t.data("offense")),e=parseInt(t.data("status")),u=[],i=[],o={init:function(){}};this.$chart=t;this.offenseId=f;this.statusId=e;this.fnSetDataState=function(n){i=n};this.fnSetDataUS=function(n){u=n};this.fnInitSparkline=function(){var a=i.length,f,h,c;if(a){var e=i[0].y,l=i[i.length-1].y,v=u.length?Math.min(i[0].y,u[0].y):i[0].y,y=u.length?Math.max(i[i.length-1].y,u[u.length-1].y):i[i.length-1].y,p=setup.getColorScale("default",1,!0),o=[],s=[];for(f=v;f<=y;f+=1)h=i.find(function(n){return n.y===f}),c=u.find(function(n){return n.y===f}),h!==undefined?o.add([Date.UTC(f,1,1),h.r]):o.add([Date.UTC(f,1,1),null]),c!==undefined?s.add([Date.UTC(f,1,1),c.r]):s.add([Date.UTC(f,1,1),null]);var w={color:"rgb("+p[0]+")",data:o,name:r.stateName},b={color:"#000",connectNulls:!0,dashStyle:"Dash",data:s,lineWidth:1,type:"line",name:"United States"},k=e===l?e:e+"&ndash;"+l;t.parent().find(".years").html(", "+k);t.empty();t.highcharts({chart:{animation:!1,backgroundColor:"transparent",marginTop:0,marginBottom:0,spacing:[0,0,0,0],type:"area",height:50},credits:{enabled:!1},legend:{enabled:!1},navigator:{enabled:!1},plotOptions:{area:{animation:!1,connectNulls:!0,marker:{enabled:!1}},line:{animation:!1,marker:{enabled:!1},states:{hover:{lineWidth:1}}}},rangeSelector:{enabled:!1},scrollbar:{enabled:!1},series:[w,b],subtitle:{text:"",x:0,y:0},title:{text:"",x:0,y:0},tooltip:{formatter:function(){var i=new Date(this.x).getUTCFullYear(),t="<strong>"+i+"<\/strong>";return n.each(this.points,function(n,i){t+='<br /><span style="color: '+i.series.color+'">'+i.series.name+"<\/span>: "+utility.formatThousands(this.y)}),t},shared:!0},xAxis:{crosshair:{width:1},type:"datetime",units:[["year",[1]]],labels:{enabled:!1},tickInterval:31536e6,tickLength:0},yAxis:{gridLineColor:"transparent",labels:{enabled:!1},maxPadding:0,minPadding:0,title:null}})}else t.removeClass("ap-chart").addClass("empty").html('Insufficient reporting coverage<br /><a class="apr-insufficient-data" href="#">Why?<\/a>')};o.init()}}();return{init:function(n){i.init(n)}}}(jQuery,webitects),jbTransferTrends=function(n,t){var f={},i={},r,e,u={init:function(o){f=n.extend(!0,{url:"/"},o);r=n("#jb-tt-chart");e=n("#jb-tt-footnotes");var s=t.ajaxHelper.resolveAjax(n.ajax({url:f.url,type:"Post"}));s.then(function(n){i=n;u.initTransferTrends()},function(){})},initTransferTrends:function(){var c,v,o,l,s;if(i!==null){var h=[],a=[],f=i;f!==undefined&&(c=setup.getColorScale("default",f.pathways.length,!0),v=jjgps.data.states.find(function(n){return n.id===f.sid}),a=f.footnotes,o=u.getMinYear(f.pathways),l=u.getMaxYear(f.pathways),f.pathways.foreach(function(n,t){var r=[],i=o,u;n.trends.foreach(function(n){var u,t;if(n[0]-i>1)for(u=n[0]-i-1,t=0;t<u;t++)r.add([Date.UTC(i+(t+1),1,1),null]);r.add([Date.UTC(n[0],1,1),n[1]]);i=n[0]});u={color:"rgb("+c[t]+")",data:r,name:n.pw};h.add(u)}));s=[];f.footnotes.foreach(function(n){var i=n.indexOf("<")===0?n:t.utility.nl2br(n);s.push(i)});e.append(s.join(""));r.empty();r.highcharts({chart:{animation:!1,marginTop:65,spacing:[4,0,0,2],type:"area"},credits:{enabled:!1},legend:{enabled:!0,itemHoverStyle:{cursor:"default"}},navigator:{enabled:!1},plotOptions:{area:{animation:!1,stacking:"normal",marker:{enabled:!1},events:{legendItemClick:function(){return!1}}},line:{color:"#31ad8b",lineWidth:4,states:{hover:{lineWidth:4}},tooltip:{valueDecimals:0}}},rangeSelector:{enabled:!1},scrollbar:{enabled:!1},series:h,subtitle:{align:"left",style:{color:"#555",fontSize:"14px"},text:"Transfer data available {0}&ndash;{1}".format(o,l),useHTML:!0,x:-2,y:35},title:{align:"left",style:{color:"#000",fontSize:"16px",fontWeight:"bold"},text:i.chart?i.chart:"Cases judicially waived to criminal court",useHTML:!0,x:-2},tooltip:{formatter:function(){var i=new Date(this.x).getUTCFullYear(),t="<strong>"+i+"<\/strong>";return n.each(this.points,function(n,i){t+='<br /><span style="color: '+i.series.color+'">'+i.series.name+"<\/span>: "+this.y}),t},shared:!0},xAxis:{crosshair:{width:1},labels:{formatter:function(){return new Date(this.value).getUTCFullYear()},style:{fontSize:"12px"},y:16},tickPositioner:function(){for(var t=[],n=Math.floor(this.dataMin),i=31536e6;n-i<=this.dataMax;n+=i)t.push(n);return t}},yAxis:{allowDecimals:!1,gridLineColor:"#ececec",labels:{align:"right",formatter:function(){return utility.formatThousands(this.value)},style:{fontSize:"12px"},x:-4,y:3},min:0,showFirstLabel:!0,showLastLabel:!0,title:null}})}else r.html("<p>Does not report data.<\/p>")},getMaxYear:function(n){var t;return n.foreach(function(n){var i=n.trends.max(function(n){return n[0]});(t===undefined||i>t)&&(t=i)}),t},getMinYear:function(n){var t;return n.foreach(function(n){var i=n.trends.min(function(n){return n[0]});(t===undefined||i<t)&&(t=i)}),t}};return{init:function(n){u.init(n)}}}(jQuery,webitects),refMonitoringMethods=function(n,t){var o={},r={},f,u,s,i={nullValue:.00043,raceOrder:[4,9,2,3],year:0},e={init:function(h){o=n.extend(!0,{ajaxUrl:"/"},h);f=n("#ref-md-year");u=n("#ref-md-chart");s=n("#ref-md-footnotes");var c=t.ajaxHelper.resolveAjax(n.ajax({url:h.ajaxUrl,type:"Post"}));c.then(function(n){r=n.data;i.year=r.max(function(n){return n.y});e.initMdChart();f.html(i.year)},function(){}).then(function(){})},initMdChart:function(){var l,f;if(r.length){var t=r,e=[],c=t.distinct(function(n){return n.rid});jjgps.data.races.foreach(function(n){if(c.indexOf(n.id)>-1){var t=i.raceOrder.indexOf(n.id);n.id===2?n.color="#9B59B6":n.id===3?n.color="#E74C3C":n.id===4?n.color="#206AA3":n.id===6?n.color="#34495E":n.id===7?n.color="#E67E22":n.id===8?n.color="#36BF99":n.id===9&&(n.color="#B3D5A0");t!==-1&&(e[t]=n)}});l=[];f=[];e.foreach(function(n){if(n!==undefined){var u={color:n.color,data:[],name:n.sname},r=t.find(function(t){return t.rid===n.id});r!==undefined&&(u.data.push({y:r.arr===null?i.nullValue:r.arr,fn1:r.arrFn1,fn2:r.arrFn2}),u.data.push({y:r.det===null?i.nullValue:r.det,fn1:r.detFn1,fn2:r.detFn2}),u.data.push({y:r.com===null?i.nullValue:r.com,fn1:r.comFn1,fn2:r.comFn2}));f.push(u)}});var o=!1,s=!1,h=!1;t.foreach(function(n){(n.arrFn1||n.detFn1||n.comFn1)&&(o=!0);(n.arrFn2||n.detFn2||n.comFn2)&&(s=!0);(n.arr===null||n.det===null||n.com===null)&&(h=!0)});o&&n('#ref-md-footnotes li[data-showif="hasfn1"]').show();s&&n('#ref-md-footnotes li[data-showif="hasfn2"]').show();h&&n('#ref-md-footnotes li[data-showif="hasnulls"]').show();u.empty();u.highcharts({chart:{animation:!1,height:300,spacing:[10,0,10,4],type:"column"},credits:{enabled:!1},legend:{borderWidth:0,itemStyle:{fontWeight:"normal"},itemHoverStyle:{cursor:"default"},margin:40,padding:30,verticalAlign:"top"},plotOptions:{column:{animation:!1,dataLabels:{crop:!1,enabled:!0,formatter:function(){var n=this.point.fn1?"*":"",t=this.point.fn2?"†":"";return(this.y===i.nullValue?"N/A":this.y.toFixed(1))+n+t},overflow:"none",style:{fontSize:"14px",fontWeight:"normal"}},events:{legendItemClick:function(){return!1}}}},series:f,title:{align:"center",style:{color:"#000",fontSize:"16px",fontWeight:"bold"},text:"Simple rates, non-white to non-Hispanic white ratios ("+t[0].y+")",useHTML:!0},tooltip:{formatter:function(){var t="<strong>"+this.x+"<\/strong>";return n.each(this.points,function(n,r){var f=this.point.low,u=this.y===i.nullValue?"N/A":this.y.toFixed(1);t+='<br/><b style="color: '+r.series.color+'">'+r.series.name+"<\/b>: "+u}),t},shared:!0},xAxis:{categories:["Arrest","Detention","Committed"],labels:{style:{color:"#000",fontSize:"12px"}},tickLength:0},yAxis:{allowDecimals:!1,labels:{formatter:function(){return this.value.toFixed(1)},style:{color:"#000",fontSize:"12px"}},min:0,plotLines:[{color:"#36bf99",width:2,value:1,label:{text:"Parity",align:"left",x:0}}],title:{text:null}}})}else u.empty().html("<p>Does not report data.<\/p>")}};return{init:function(n){e.init(n)}}}(jQuery,webitects),soiReportedData=function(n,t){var u={},i={},r,f,e={init:function(o){u=n.extend(!0,{ajaxUrl:"/"},o);r=n("#soi-rd-chart");f=n("#soi-rd-footnotes");var s=t.ajaxHelper.resolveAjax(n.ajax({url:u.ajaxUrl,type:"Post"}));s.then(function(n){i=n.charts.length?n.charts[0]:undefined;i!==undefined?(i.types=n.types,e.initChart()):r.html("<p>Does not report data.<\/p>")},function(){}).then(function(){})},initChart:function(){var o="rate",c=[],u=[],l=[],a,v,s,h,e;for(c=i.types.findAll(function(n){return n.id===1||n.id===2}),c.foreach(function(n){l.push("#{0}".format(n.color))}),a=i.data.min(function(n){return n.y}),v=i.data.max(function(n){return n.y}),s=a;s<=v;s++)u.push(s);h=[];c.foreach(function(n){var t=[];u.foreach(function(r){var u=i.data.find(function(t){return t.y===r&&t.tid===n.id});u===undefined?t.push(null):o==="raw"?t.push(u.count):o==="rate"&&t.push(u.per1000)});t.length>0&&h.push({data:t,name:n.typeShort})});e=h.max(function(n){return n.data.max()});o==="raw"?e=parseInt(e/1e3)*1e3+1e3:o==="rate"&&(e=parseInt(e/50)*50+50);i.notes!==null&&i.notes.length&&i.notes[0]==="<"&&(i.notes="<p>{0}<\/p>".format(t.utility.nl2br(i.notes)));f.append(i.notes);r.highcharts({chart:{animation:!1,height:450,spacing:[0,0,10,2]},colors:l,credits:{enabled:!1},legend:{borderWidth:0,itemStyle:{fontSize:"16px",fontWeight:"normal"},itemHoverStyle:{cursor:"default"},margin:20,verticalAlign:"top",y:20},plotOptions:{line:{events:{legendItemClick:function(){return!1}},lineWidth:4,marker:{radius:5}}},series:h,subtitle:{align:"left",style:{color:"#555",fontSize:"14px"},text:"Data available: "+u[0]+"&ndash;"+u[u.length-1],useHTML:!0,y:35},title:{align:"left",style:{color:"#000",fontSize:"16px",fontWeight:"bold"},text:i.title,useHTML:!0},tooltip:{formatter:function(){var t="<strong>"+this.x+"<\/strong>";return n.each(this.points,function(){var i=this.point.low,n=this.y!==null?utility.formatThousands(this.y):"N/A";t+="<br />"+this.series.name+": "+n}),t},shared:!0},xAxis:{categories:u,labels:{formatter:function(){return this.value.toString()},style:{color:"#000",fontSize:"14px"},y:22},tickLength:5,tickmarkPlacement:"on"},yAxis:{allowDecimals:!1,labels:{formatter:function(){return utility.formatThousands(this.value)},style:{color:"#000",fontSize:"14px"}},max:e,min:0,offset:-5,title:{text:null}}})}};return{init:function(n){e.init(n)}}}(jQuery,webitects),siReportedData=function(n,t){var o={},i={},r,u,f={init:function(e){o=n.extend(!0,{ajaxUrl:"/"},e);r=n("#si-rd-chart");u=n("#si-rd-footnotes");var s=t.ajaxHelper.resolveAjax(n.ajax({url:e.ajaxUrl,type:"Post"}));s.then(function(n){i=n.charts.length?n.charts[0]:null;f.initChart()},function(){}).then(function(){})},initChart:function(){var f;if(i!==null&&i.types.length){var h=[],c=setup.getColorScale("default",i.types.length,!0),o=e.getMinYear(i.types),s=e.getMaxYear(i.types),l="Data available "+(o===s?s:o+"&ndash;"+s);n("#si-rd-chart-title").html(i.title);n("#si-rd-chart-subtitle").html(l);i.types.foreach(function(n,t){for(var r=[],e=o,u,f,i=o;i<=s;i++)u=n.data.find(function(n){return n.year===i}),u!==undefined?r.push([Date.UTC(i,1,1),u.count]):r.push([Date.UTC(i,1,1),null]);f={color:"rgb("+c[t]+")",data:r,name:n.type};h.push(f)});f=i.footnotes;f!==null&&f!==undefined&&f.length&&f[0]!=="<"&&(f="<p>"+t.utility.nl2br(f)+"<\/p>");u.html(f);r.highcharts({chart:{animation:!1,marginTop:10,spacing:[0,0,0,5],type:"line"},credits:{enabled:!1},legend:{enabled:!0,itemHoverStyle:{cursor:"default"}},navigator:{enabled:!1},plotOptions:{line:{animation:!1,color:"#31ad8b",events:{legendItemClick:function(){return!1}},lineWidth:4,marker:{enabled:!0},states:{hover:{lineWidth:4}},tooltip:{valueDecimals:0}}},rangeSelector:{enabled:!1},scrollbar:{enabled:!1},series:h,title:{text:null},tooltip:{formatter:function(){var i=new Date(this.x).getUTCFullYear(),t="<b>"+i+"<\/b>";return n.each(this.points,function(n,i){var r=i.y===null?"Did not report":utility.formatThousands(i.y);t+='<br/><b style="color: '+i.series.color+'">'+i.series.name+"<\/b>: "+r}),t},shared:!0},xAxis:{labels:{formatter:function(){return new Date(this.value).getUTCFullYear()},style:{fontSize:"12px"},y:16},tickPositioner:function(){for(var t=[],n=Math.floor(Date.UTC(o,1,1)),i=31536e6;n-i<=Date.UTC(s,1,1);n+=i)t.push(n);return t}},yAxis:{allowDecimals:!1,gridLineColor:"#ececec",labels:{align:"right",formatter:function(){var n=utility.formatThousands(this.value);return n},style:{fontSize:"12px"},x:-4,y:3},min:0,showFirstLabel:!0,showLastLabel:!0,title:null}})}else r.parent().html("<p>Does not report data.<\/p>")}},e={getMaxYear:function(n){var t;return n.foreach(function(n){var i=n.data.max(function(n){return n.year});(t===undefined||i>t)&&(t=i)}),t},getMinYear:function(n){var t;return n.foreach(function(n){var i=n.data.min(function(n){return n.year});(t===undefined||i<t)&&(t=i)}),t}};return{init:function(n){f.init(n)}}}(jQuery,webitects)