/*
var chart;
$(document).ready(function() {
   chart = new Highcharts.Chart({
      chart: {
         renderTo: 'workout-summary-statistics-1',
         defaultSeriesType: 'column',
         backgroundColor: '',
         marginLeft: 20,
         marginTop: 10,
         marginBottom: 30,
         marginRight: 30
      },
      title: {
         text: null
      },
      xAxis: {
         categories: [
            'Jan', 
            'Feb', 
            'Mar', 
            'Apr', 
            'May', 
            'Jun', 
            'Jul'
         ]
      },
      yAxis: {
          gridLineWidth: 0,
         min: 0,
         title: null,
         offset: 200
      },
      legend: null,
      tooltip: {
         formatter: function() {
            return ''+
               this.x +': '+ this.y +' mm';
         }
      },
      plotOptions: {
         column: {
            pointPadding: 0.2,
            borderWidth: 0
         }
      },
       series: [{
         name: 'Tokyo',
         data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6]
   
      }, {
         name: 'New York',
         data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6]
      }, {
         name: 'Berlin',
         data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6]
   
      }]
   });
   

});
*/   

jQuery.noConflict();
     
var workout_summary; // globally available
//$(document).ready(function() {
// Put all your code in your document ready area
jQuery(document).ready(function($){

	// define the options
	var options = {
		chart: {
			renderTo: 'workout-summary-statistics-1',
			defaultSeriesType: 'column',
			backgroundColor: '',
            marginLeft: 20,
            marginTop: 10,
            marginBottom: 30,
            marginRight: 30
		},
		credits: {
		    enabled: false
		},
        colors: [
        	'#343434', 
        	'#686868', 
        	'#999', 
        	'#d0d0d0', 
        	'#51bde7', 
            '#2e617f', 
            '#499ccc', 
            '#5cc3ff', 
            '#c5eaff'
        ],
		labels: {
		    style: {
		        color: '#51bde7'
		    }
		},
		title: {
		    text: null
		},
		xAxis: {
		    lineColor: '#ccc',
		    tickInterval: 3,
		    labels: {
		        style: {
		            fontSize: '9px'
		        }
		    },
		    categories: []
		},
		yAxis: [{ // Primary yAxis
		    gridLineWidth: 0,
		    offset: 100,
			title: {
				text: null
			}
		},{ // Socondary yAxis
		    gridLineWidth: 0,
		    offset: 100,
			title: {
				text: null
			}
		},{ // Third yAxis
		    gridLineWidth: 0,
		    offset: 100,
			title: {
				text: null
			}
		}],
		legend: {
			enabled: false
		},
		tooltip: {
			formatter: function() {
			    if (this.series.name == 'Vikt')
	                return ''+ this.series.name + ' ' + this.x +': '+ this.y +'kg';
	            else if (this.series.name == 'Tränad sträcka')
	                return ''+ this.series.name + ' ' + this.x +': '+ this.y +'km';
                return ''+ this.series.name + ' ' + this.x +': '+ this.y +'min';
			}
		},
		plotOptions: {
		    column: {
		        shadow: false
		    }
		},
		series: []
	}
	
	jQuery.getJSON('/statistics/summary/?randNum=' + new Date().getTime(), null, function(data) {
		options.series.push({
			name: 'Vikt',
			data: data.weight,
			yAxis: 0
		});
		options.series.push({
			name: 'Tränade minuter',
			data: data.minutes,
			yAxis: 1
		});
		options.series.push({
			name: 'Tränad sträcka',
			data: data.distance,
			yAxis: 2
		});
		
		workout_summary = new Highcharts.Chart(options);
        // Set the xlabel with given data		
		if (workout_summary.xAxis && workout_summary.xAxis.length > 0) {
    		workout_summary.xAxis[0].setCategories(data.title);
        }
	});
	
});

