var init = 0;

$(document).ready( function() {
  init = 1;
  var crimeTypes=[]; //designer: list of crimes
  crimeTypes['HOMICIDE'] = 1;
  crimeTypes['RAPE']     = 2;
  crimeTypes['ROBBERY']  = 3;
  crimeTypes['ASSAULT'] = 4;
  crimeTypes['BURGLARY'] = 5;
  crimeTypes['THEFT'] = 6;
  crimeTypes['STOLEN_VEHICLE'] = 7;
  $('#movingAverage').change( function() {
    switchMovingAverage($(this).val());
  });
  $('#crimeTypeSelections').children().each( function() {
    $(this).click( function() {
      var typeString = $(this).attr('id').split('crime_type_li_')[1].split('chart')[0];
      var crimeTypeNumber = crimeTypes[typeString];
      toggleLine(crimeTypeNumber);
      $(this).parent().find('.selected').removeAttr('class');
      $(this).attr('class', 'selected');
    });
  });
});
function toggleLine(i) 
{
  var flexApp = FABridge.b_chart.root();
  flexApp.toggleLine(i);
  if (init)
    beAPageViewWhore();
}
function switchMovingAverage(i)
{
  var flexApp = FABridge.b_chart.root();
  flexApp.setMovingAverageRange(i);
  flexApp.switchMovingAverage();
  beAPageViewWhore();
}
function beAPageViewWhore()
{
  $('iframe').each( function() { 
    this.src = this.src + '?r=' + Math.round(Math.random()*1000000);
  });
}