var yMin = 180;
var bfCalc = function(weight, bfPercent){
    return (weight-yMin)*bfPercent + yMin;
}
var leanCalc = function(weight, bfPercent){
    return (weight-yMin)*(1-bfPercent) + yMin;
}
var paleoWeight = [210, 211, 207, 203.7, 201.2, 200.8, 196, 196.4, 194.8];
var paleoBf = [.22, .22, .21, .21, .19, .18, .18, .18, .18];
var paleoDates = [
            '5/29/11',
            '6/5/11', 
            '6/12/11', 
            '6/19/11', 
            '6/26/11',
            '7/3/11',
			'7/10/11',
			'7/17/11',
			'7/24/11'];

var getBfWeight = function(){
    var bfWeight = [];
    for (var i = 0; i < paleoWeight.length; i++){
        bfWeight[i] = bfCalc(paleoWeight[i], paleoBf[i]);
    }
    return bfWeight;
}
var getLeanWeight = function(){
    var leanWeight = [];
    for (var i = 0; i < paleoWeight.length; i++){
        leanWeight[i] = leanCalc(paleoWeight[i], paleoBf[i]);
    }
    return leanWeight;
}
var chart;

$(document).ready(function() {
if ($('#weight-container').length !== 0)
{
   chart = new Highcharts.Chart({
      chart: {
         renderTo: 'weight-container',
         defaultSeriesType: 'areaspline'
      },
      title: {
         text: 'Weight During Paleo Challenge'
      },
      legend: {
         layout: 'vertical',
         align: 'left',
         verticalAlign: 'top',
         x: 150,
         y: 100,
         floating: true,
         borderWidth: 1,
         backgroundColor: Highcharts.theme.legendBackgroundColor || '#FFFFFF'
      },
      xAxis: {
         categories: paleoDates,
         plotBands: [{ // visualize the weekend
            from: 0,
            to: 1.5,
            color: 'rgba(68, 170, 213, .2)',
            label: {
                text: 'Before Paleo Challenge',
                style: {
                    color: 'rgba(180, 180, 180, .8)'
                }
            }
         }]
      },
      yAxis: {
         title: {
            text: 'Weight'
         },
         min: yMin
      },
      tooltip: {
         formatter: function() {
                   return ''+
               this.x +': '+ this.y +' lbs';
         }
      },
      credits: {
         enabled: false
      },
      plotOptions: {
         areaspline: {
            fillOpacity: 0.5
         }         
      },
      series: [{
         showInLegend: false //empty set so that mine is blue
      },{
         name: 'Weight',
         showInLegend: true,
         data: paleoWeight
      }
      ,{
         name: '% Body Fat',
         enableMouseTracking: false,
         showInLegend: true,
         marker: {
            enabled: false
         },
         data: getBfWeight()
      }]
   });
   
}   
});


