/*
 * Mazama_databrowser.js
 *
 * Jonathan Callahan
 * http://mazamascience.com
 *
 * Default behavior for Mazama Science databrowsers.
 *
 * 1) Any change to an element in the form should trigger a plot request so that the current state
 *    of the UI always reflects the parameters used to generate the plot.
 * 2) Each successful response contains a url for the plot and one for the pdf version of the plot.
 *
 */

function handleJSONResponse(JSONResponse) {
// TODO:  check the status for possible errors
  $('#spinner').hide();
  $('#plot').attr('src',JSONResponse.img_url);
  $('#pdf').attr('href',JSONResponse.pdf_url);
}

function requestImage() {
  $('#spinner').fadeIn(4000);
  var url = '/cgi-bin/Rheumatology.cgi';
  data = $('#controls_form').serialize();
  $.getJSON(url, data, handleJSONResponse);
}

$(function() {
  $('#spinner').hide();
  $('#subset').bind('change',requestImage);
//  $('#plottype').bind('change',selectPlotType);
//  $('#xvar').bind('change',requestImage);
//  $('#yvar').bind('change',requestImage);
  $('#zvar').bind('change',requestImage);
//  $('#zval').bind('change',requestImage);

  // Set up tooltips 
  $('span.tooltip').cluetip({width: '400', attribute: 'id', hoverClass: 'highlight'});
});

