/* Author: 

*/
   
var chart;

/*function get_data() {
		var id = 2; 
		$.ajax({
			url: 'get_data.php?id=3'+id,
			success: function(point) {
				
				//console.log(point);
				//var obj = $.parseJSON(point);
				var data = [];
				for (x in point) {
					//console.log(point[x]['power']);
					data.push(point[x]['power']);
					id = point[x]['id'];
				}
  
				
				console.log(data);
				//console.log(id);
				
				//point = parseInt(point);
				
				if(data.length < 1) {
					chart.series[0].addPoint(0);
				} else {
					//for (x in data) {
						chart.series[0].addPoint(data);
					//}
				}
				//$('#data').text(point+'W');
				
				//setInterval("console.log('hi!');", 1000);
				
				// call it again after one second
				setTimeout(get_data(id), 1000000);    
			},
			cache: false
		});
}
	
function get_single_value() {
	$.ajax({
		url: 'get_single.php',
		success: function(point) {
  
				console.log(point);
				
				// call it again after one second
				//setTimeout(get_single_value(), 5000);    
		}
	});
}*/

$(document).ready(function(){

	console.log('Hello');
	
	//setInterval(get_single_value(), 1000);
	
	$('#killswitch').click(function() { 
		console.log('Kill');
		// Ajax call with appliance id returning json data of appliance
		$.ajax({
			type: "POST",
			url: "kill.php",
			data: ({
				kill : true,
				current: curstatus
			}),
			success: function(msg){
				console.log(msg);
				if(curstatus == 1) {
					curstatus = 0;
					$('#status').text(msg).removeClass('live').addClass('dead')
					$('#killswitch').attr('value','Restore');
				} else {
					curstatus = 1;
					$('#killswitch').attr('value','Kill');
					$('#status').text(msg).removeClass('dead').addClass('live');
				}
			}
		});
		
		return false;
	});
	
   // Single chart
  /*if($('#graph').length) {
	   var backgroundColour = '#FFFFFF';
	   var chartColour = '#468F5F';
	   chart = new Highcharts.Chart({
		  chart: {
			 renderTo: 'graph',
			 margin: [50, 0, 0, 0],
			 plotBackgroundColor: 'none',
			 plotBorderWidth: 0,
			 defaultSeriesType: 'spline',
			 plotShadow: false ,
			 events: {
				load: get_data()
			},
			backgroundColor : backgroundColour
		  },
		  title: {
			 text: 'S.E.U.N. Power Consumption'
		  },
		  tooltip: {
			enabled: false 
		  },
		   series: [{
			 data: []
		  }]
	   });
	}*/

});


