$(document).ready(function() {
  $.get("/ajax.php", '', function(json) { setupOptions(json); }, "text");

  function setupOptions(json) {
    options = $.secureEvalJSON(json);
    $('#selector').append('<option selected="selected" value="">Select a symptom</option>');
    jQuery.each(options, function() {
      $('#selector').append('<option value="' + this.anchor + '">' + this.title + '</option>');
    });
  }
  
  $("#selector").change(function () {
    var anchor = $("#selector").val();
    if(anchor != '') {
      var element = $('a[name=' + anchor + ']');
      if(element.length > 0) {
        $('html, body').animate({scrollTop : element.offset().top}, "slow");
      } else {
        document.location = '/where-does-it-hurt/#' + anchor;
      }
    }
  })

  $("area").click(function () {
    var href = $(this).attr('href');
    var anchori = href.indexOf('#');
    var anchor = href.substring(anchori + 1, href.length);   
    var element = $('a[name=' + anchor + ']');
    if(element.length > 0) {
      $('html, body').animate({scrollTop : element.offset().top}, "slow");
      return false;
    }
  })  
  
});


