var ofc_ready=function(){},open_flash_chart_data=function(){return JSON.stringify(getEmptyChartData())},getEmptyChartData=function(){var n={};return $.ajax({url:"/Chart/GetEmpty",type:"POST",async:!1,cache:!0,success:function(t){n=t}}),n};(function(n){var i=function(){var t=this;t.timelineIntervalHandler=null;t.foo=ko.observable(null);t.models=ko.observableArray([]);t.scenarios=ko.observableArray([]);t.regions=ko.observableArray([]);t.variables=ko.observableArray([]);t.legendKeys=ko.observableArray([]);t.graphData=ko.observable();t.selectedChartType=ko.observable();t.selectedModels=ko.observableArray([]);t.selectedScenarios=ko.observableArray([]);t.selectedRegions=ko.observableArray([]);t.selectedVariables=ko.observableArray([]);t.idle=ko.observable(!0);t.chartHasData=ko.computed(function(){var i=t.graphData();switch(t.selectedChartType()*1){case 1:return i&&!n.isArray(i)&&i.elements&&i.elements.length;case 2:return i&&n.isArray(i)&&i.length}});t.isLinePlotChart=ko.computed(function(){return t.selectedChartType()==="1"});t.isStackedBarsChart=ko.computed(function(){return t.selectedChartType()==="2"});t.chartClassNames=ko.computed(function(){return t.isLinePlotChart()?{checkbox:"dynatree-radio"}:null});t.chartSelectMode=ko.computed(function(){return t.isLinePlotChart()?1:2});t.timelineInterval=ko.observable(3);t.initialChartHeight=ko.observable(400);t.chartHeight=ko.computed(function(){var n=t.initialChartHeight();return t.isLinePlotChart&&(n+=(Math.floor(t.selectedModels().length*t.selectedScenarios().length*t.selectedRegions().length/3)+1)*16),n});t.showDataOnChart=function(i){var f=n("#chart")[0],o,u,e,r;if(i&&f&&f.load){if(f.load(JSON.stringify(i)),o=t.initialChartHeight(),u=1,t.legendKeys([]),t.isLinePlotChart()&&i.elements){for(u=i.elements.length,e=0;e<u;e++)r=i.elements[e],r._text&&t.legendKeys.push({label:r._text,color:r.colour.replace("#",""),dot:r["dot-style"].type,dotColor:r["dot-style"].colour.replace("#",""),sides:r["dot-style"].sides,on:r["line-style"].on+1,off:r["line-style"].off-1});u=0}else t.isStackedBarsChart()&&i.elements.length&&(u=i.elements[0].keys.length);o+=(Math.floor((u-1)/3)+1)*16;f.setAttribute("height",o+"")}};t.resetTimeline=function(){n("#timeline").find("#dates li a:first").click()};t.getData=function(){t.selectedModels().length>0&&t.selectedScenarios().length>0&&t.selectedRegions().length>0&&t.selectedVariables().length>0?n.ajax({url:"/Chart/GetData",type:"POST",async:!1,data:{chart:t.selectedChartType(),models:t.selectedModels(),scenarios:t.selectedScenarios(),regions:t.selectedRegions(),variables:t.selectedVariables()},traditional:!0,success:function(n){t.graphData(n)}}):t.graphData([])}},t=new i;t.selectedChartType.subscribe(function(){t.selectedVariables([])});t.selectedModels.subscribe(t.getData);t.selectedRegions.subscribe(t.getData);t.selectedScenarios.subscribe(t.getData);t.selectedVariables.subscribe(t.getData);t.timelineInterval.subscribe(function(){t.resetTimeline()});ko.bindingHandlers.multiSelect={init:function(t,i,r){var u=r().multiSelectOptions||{};n(t).multiselect({header:!1,multiple:u.multiple===!0,noneSelectedText:u.noneSelectedText,minWidth:"250",selectedList:15,click:function(){return n(this).multiselect("widget").find("input:checked").length<=15},close:function(){},position:{my:"left bottom",at:"left bottom",of:"#scenarios"}});ko.utils.domNodeDisposal.addDisposeCallback(t,function(){n(t).multiselect("destroy")})}};ko.bindingHandlers.dynaTree={init:function(i){n.ajax({url:"/Chart/GetVariables",type:"POST",success:function(n){t.variables(n)}});ko.utils.domNodeDisposal.addDisposeCallback(i,function(){n(i).dynatree("destroy")})},update:function(i){n(i).dynatree("destroy");n(i).children("ul").empty();n(i).dynatree({checkbox:!0,classNames:t.chartClassNames(),selectMode:t.chartSelectMode(),children:t.variables(),imagePath:"/Content/Images/dynatree/",onSelect:function(i,r){var u=r.tree.getSelectedNodes(),f=n.map(u,function(n){return n.data.hasData?n.data.id:null});t.selectedVariables(f)}})}};ko.bindingHandlers.openFlashChart={init:function(t){swfobject.embedSWF("/Scripts/open-flash-chart.swf",n(t).children().attr("id"),"650","400","9.0.0","/Scripts/expressInstall.swf")},update:function(n,i){var u=i(),r=ko.utils.unwrapObservable(u),f=t.chartHasData()?t.selectedChartType()*1==1?r:r[0].data:getEmptyChartData();t.showDataOnChart(f)}};ko.bindingHandlers.timeLine={init:function(i){n(i).find("#dates > li > a").on("click",function(){var i=n(this),r;clearTimeout(t.timelineIntervalHandler);t.isStackedBarsChart()&&n.isArray(t.graphData())&&t.graphData().length>0&&(r=_.chain(t.graphData()).filter(function(n){return n.year==i.text()}).first().value(),t.showDataOnChart(r.data),t.timelineInterval()*1>0&&(t.timelineIntervalHandler=setTimeout(function(){i.parent().next().children().click()},t.timelineInterval()*1e3)))});n().timelinr()},update:function(){t.resetTimeline()}};n(function(){ko.applyBindings(t)})})(jQuery)