var root=null;var username=null;var maxTime=new Date().getTime();var timezoneOffset=0;var maxPower=null;var maxStackedPower=null;var masterGraph=null;var zoomedGraph=null;var masterSeries=null;var zoomedSeries=null;var zoomedRange=null;var rangeHistory=[];var rangeFuture=[];var colors=["#edc240","#afd8f8","#cb4b4b","#4da74d","#9440ed","#27408B"];var timeUnitSize={second:1000,minute:60*1000,hour:60*60*1000,day:24*60*60*1000,month:30*24*60*60*1000,year:365.2425*24*60*60*1000};var minZoomedTimespan=15*60000;function yaxisTickFormater(B,A){return parseInt(B)+"&nbsp;W"}function xaxisTickFormater(G,F){var D=F.tickSize[0]*timeUnitSize[F.tickSize[1]];var E=F.max-F.min;var A=null;if(D<timeUnitSize.day){if(E<timeUnitSize.day){A="g:ia"}else{if(E<2*timeUnitSize.day){A="ga"}else{A="M j, ga"}}}else{if(D<timeUnitSize.month){if(E<timeUnitSize.month){A="D M j"}else{A="M j"}}else{if(D<timeUnitSize.year){if(E<timeUnitSize.year){A="M"}else{A="M y"}}else{A="y"}}}var B=new Date(G);var C=B.format(A);if(C=="12:00am"||C=="12am"){return B.format("D M j")}else{return C}}function toStackedData(C){if(C.length==0){return C}else{var B=$.map(C[0].data,function(){return 0});var A=function(H){var G=new Array();for(var F in H){var E=H[F];var D=E[0];var I=E[1];B[F]+=I;if(B[F]>maxStackedPower){maxStackedPower=B[F]}G.push([D,B[F]])}return G};return $.map(C,function(F,D){var E=$.extend({},F);E.data=A(F.data);E.lines.fill=true;return E}).reverse()}}function isStacked(){return $("#stacked").attr("checked")}function showMasterSeries(A){if(isStacked()){A=toStackedData(A)}masterGraph=$.plot($("#master-graph"),A,{yaxis:{min:0,ticks:0,tickFormatter:yaxisTickFormater},xaxis:{mode:"time",tickFormatter:xaxisTickFormater},lines:{show:true,lineWidth:1},grid:{borderWidth:1},legend:{show:false},selection:{mode:"x",color:"#bbbbd0"},shadowSize:0});if(zoomedRange){masterGraph.setSelection({xaxis:zoomedRange},false)}}function showZoomedSeries(D){var C=isStacked();var E=$("#autoscale").attr("checked");if(C){D=toStackedData(D)}var A=E?undefined:C?maxStackedPower:maxPower;var B={mode:(zoomedRange.to-zoomedRange.from)>minZoomedTimespan?"x":null,color:"#bbbbc8"};zoomedGraphed=$.plot($("#graph"),D,{yaxis:{min:0,max:A,tickFormatter:yaxisTickFormater},xaxis:{mode:"time",min:zoomedRange.from,max:zoomedRange.to,tickFormatter:xaxisTickFormater},grid:{borderWidth:1},legend:{show:false},selection:B})}function filterSeries(B){var A=[];$.each(B,function(C){if($("#appliance"+C+" input").attr("checked")){this.color=colors[C%colors.length];this.lines={fillColor:RGBA.parse(this.color).toString(true)};A.push(this)}});return A}function filtersChanged(){if($("div.appliance-filter input:checked").length==0){$($("div.appliance-filter input").get(0)).attr("checked",true)}showMasterSeries(filterSeries(masterSeries));if(zoomedSeries){showZoomedSeries(filterSeries(zoomedSeries))}}function showLoadingThrobber(){$("#graph").append($.createElement("div #throbber-overlay")).append($.createElement("div #throbber"))}function hideLoadingThrobber(){$("#throbber-overlay").remove();$("#throbber").remove()}function formatGraphTitle(B){var A="D M j, g:ia";return new Date(B.from).format(A)+" &mdash; "+new Date(B.to).format(A)}function zoomTo(A,B){showLoadingThrobber();$("#graph-title").html("Loading...");if(B&&zoomedRange){rangeHistory.push(zoomedRange);rangeFuture=[];$("#back").removeClass("disabled").addClass("enabled");$("#next").removeClass("enabled").addClass("disabled")}zoomedRange=A;$.getJSON("graph.json?from="+A.from+"&to="+A.to,function(C){zoomedSeries=C;showZoomedSeries(filterSeries(C));hideLoadingThrobber();$("#graph-title").html(formatGraphTitle(A))})}function previousRange(){if(rangeHistory.length>0){rangeFuture.push(zoomedRange);var A=rangeHistory.pop();if(rangeHistory.length===0){$("#back").removeClass("enabled").addClass("disabled")}$("#next").removeClass("disabled").addClass("enabled");masterGraph.setSelection({xaxis:A},true);zoomTo(A,false)}}function nextRange(){if(rangeFuture.length>0){rangeHistory.push(zoomedRange);var A=rangeFuture.pop();$("#back").removeClass("disabled").addClass("enabled");if(rangeFuture.length===0){$("#next").removeClass("enabled").addClass("disabled")}masterGraph.setSelection({xaxis:A},true);zoomTo(A,false)}}function lastTimeRange(C){var B=maxTime-C;var A={from:B,to:maxTime};masterGraph.setSelection({xaxis:A},true);zoomTo(A,true)}function lastDayRange(){lastTimeRange(24*60*60*1000)}function lastWeekRange(){lastTimeRange(7*24*60*60*1000)}function lastMonthRange(){lastTimeRange(30*24*60*60*1000)}$(function(){$("#back").click(previousRange);$("#next").click(nextRange);$("#filters input, #stacked, #autoscale").click(filtersChanged);if(applianceCount==1){$("div.appliance-filter input").hide()}if(masterSeries.length==0){$("#graph-title").text("No Data Available");$("#master-blaster").hide()}else{showMasterSeries(filterSeries(masterSeries));$.each(masterSeries,function(C){$("#appliance"+C+" .color-patch").css("background-color",colors[C%colors.length])});$("#master-graph").bind("plotselected",function(D,C){zoomTo(C.xaxis,true)});$("#graph").bind("plotselected",function(D,C){masterGraph.setSelection({xaxis:C.xaxis})});var A=maxTime-24*60*60*1000;var B={from:A,to:maxTime};masterGraph.setSelection({xaxis:B})}});