if (Drupal.jsEnabled) {
  $(document).ready(function () {
    // handle general settings config form
    avs_config_handler();
    $("input[@name=disable_user_upload]").bind("click", avs_config_handler);


    // handle user account radio buttons
    $('div.user_avatar_select input.form-radio').hide();

    $('div.user_avatar_select img').hover(
      function(){
        $(this).addClass("avatar_hover");
      },
      function(){
        $(this).removeClass("avatar_hover");
      }
    );

    $('div.user_avatar_select img').bind("click",function(){
      $("div.user_avatar_select img.avatar_select").each(function(){
        $(this).removeClass("avatar_select");
        $(this).parent().children("input").attr("checked","");
      });
      $(this).addClass("avatar_select");
      $(this).parent().children("input").attr("checked","checked");
    });
  });
}

function avs_config_handler(event) {
  // enable / disable "force_set_image"
  if ($("input[@name=disable_user_upload]:checked").val() == 1) {
    $("input[@name=force_set_image]").removeAttr("disabled");
  }
  else {
    $("input[@name=force_set_image]").attr("disabled", "disabled");
  }
}
