   function drawPlots(stats){                                
                var speedPlot = drawSpeedPlot(stats.speed,0,0,0,0);
                var altPlot = drawAltPlot(stats.alt,0,0,stats.alt1,stats.alt2);
                                 
                          
                // now connect the two
                var internalSelection = false;
                
                //listener for alt chart
                jQuery("#altstats").bind("selected", function (event, area) {
                  // do the zooming
                  drawAltPlot(stats.alt,area.x1,area.x2,area.y1,area.y2);  
                  
                  if (internalSelection)
                  return; // prevent eternal loop
                  internalSelection = true;
                  internalSelection = false;
                });                 
                
                //listener for speed chart
                jQuery("#speedstats").bind("selected", function (event, area) {
                  // do the zooming
                  drawSpeedPlot(stats.speed,area.x1,area.x2,area.y1,area.y2);
                                                  
                  if (internalSelection)
                  return; // prevent eternal loop
                  internalSelection = true;
                  internalSelection = false;
                });  
                   
                jQuery("#speedstats").bind("dblclick", function (event) {                
                  speedPlot.clearSelection();
                  drawSpeedPlot(stats.speed,0,0,0,0);                                      
                  internalSelection = false;
                 });  
                 jQuery("#altstats").bind("dblclick", function (event) {                
                  altPlot.clearSelection();
                  drawAltPlot(stats.alt,0,0,0,0);                
                  internalSelection = false;
                 }); 
               } 
               
        function getAxisOptions(x1,x2,y1,y2){
                return axisOptions = {
                    xaxis: {
                          ticks: stats.time,
                          mode: "time",          
                          timeformat: "%H:%M",
                          min: x1, 
                          max: x2 
                          },
                    yaxis: {
                          min: y1, 
                          max: y2 
                          },                          
                    selection: { mode: "xy" },
                      grid : {
                        backgroundColor: "rgb(247,247,247)"
                      }                           
                    };  
              } 
              
              function drawSpeedPlot (speedStats,x1,x2,y1,y2){              
                  if (x2 == 0){
                    x2 = undefined;
                  }    
                  if (y2 == 0){
                    y2 = undefined;
                  }                               
                  var axisOptions = getAxisOptions(x1,x2,y1,y2) ;
               
                  var speedPlot = jQuery.plot(jQuery("#speedstats"), [ 
                    { 
                      label: lang.speed,
                      data: speedStats,
                      color: "rgb(60,116,165)",
                      lines: {
                        show: true, 
                        fill: true, 
                        fillColor: "rgb(235,235,235)" 
                       }                              
                    }
                    ] ,
                     axisOptions          
                    );
                  return speedPlot;
              }
              
              function drawAltPlot(altStats,x1,x2,y1,y2){
                  if (x2 == 0){
                    x2 = undefined;                    
                  }
                  if (y2 == 0){
                    y2 = undefined;
                  }              
                  var axisOptions = getAxisOptions(x1,x2,y1,y2) ;
               
                  var plot = jQuery.plot(jQuery("#altstats"), [ 
                    { 
                      label: lang.alt,
                      data: altStats,
                      color: "rgb(74,179,113)",
                      lines: {
                        show: true, 
                        fill: true, 
                        fillColor: "rgb(237,250,241)" 
                       }                               
                    }
                    ] ,
                     axisOptions          
                    );
                  return plot;              
              
              
              }
              
            
