dojo.require("dojox.charting.Theme");

(function(){
	var dxc=dojox.charting;
	halloweenTheme=new dxc.Theme({
		chart:{
			stroke:null,
			fill: "transparent"
		},
		plotarea:{
			stroke:null,
			fill: "transparent"
		},
		axis:{
			stroke:{ color:"#fff",width:2 },
			line:{ color:"#fff",width:1 },
			majorTick:{ color:"#fff", width:2, length:12 },
			minorTick:{ color:"#fff", width:1, length:8 },
			font:"normal normal normal 8pt Tahoma",
			fontColor:"#999"
		},
		series:{
			outline:{ width:1, color:"#fff" },
			stroke:{ width:2, color:"#666" },
			fill:new dojo.Color([0x66, 0x66, 0x66, 0.8]),
			font:"normal normal normal 7pt Tahoma",	//	label
			fontColor:"#000"
		},
		marker:{	//	any markers on a series.
			stroke:{ width:2 },
			fill:"#333",
			font:"normal normal normal 7pt Tahoma",	//	label
			fontColor:"#000"
		},
		colors:[]
	});
	halloweenTheme.defineColors({hue:82,saturation:60,low:40,high:88});
})();

drawChart=function(inArray,chartName)
{
	var chart = new dojox.charting.Chart2D(chartName);
	chart.setTheme(halloweenTheme);
	chart.addPlot("default",
	             {type:"Pie",font:"normal normal bold 10pt Times",fontColor:"000"});
	chart.addSeries("Winners", inArray);
	chart.render();
};

function makeChart(jsonFilename,chartName)
{
      dojo.xhrGet( {
        // The following URL must match that used to test the server.
        url: './'+jsonFilename, 
        handleAs: "json",

        timeout: 5000, // Time in milliseconds

        // The LOAD function will be called on a successful response.
        load: function(responseObj, ioArgs) {
          drawChart(responseObj['items'],chartName);
          return responseObj;
        },

        // The ERROR function will be called in an error case.
        error: function(responseObj, ioArgs) {
          console.error("HTTP status code: ", ioArgs.xhr.status);
          return responseObj;
          }
        });
}

function startItUp()
{
  makeChart('getWinnersByState.json','stateschart');
  makeChart('getWinnersByTown.json','townschart');
  makeChart('getHighSchoolWinners.json','highschoolchart');
  makeChart('getMiddleSchoolWinners.json','middleschoolchart');
  makeChart('getElementarySchoolWinners.json','elementaryschoolchart');
}

dojo.addOnLoad(startItUp);

