(function($) {

  $(function() {

    /* toggle evn radio buttons */
    var toggleEvnRadios = function() {
      if ($(".itemisedBill").length > 0) {
        var evnSetting = $(".itemisedBill input[type=radio]:checked").attr("class");
        $("#evnInputHintPrivate span").hide();
        $("#evnInputHintPrivate ." + evnSetting).show();
      }
    };
    $(".itemisedBill input[type=radio]").each(toggleEvnRadios).change(toggleEvnRadios);

    /* initialize fieldset choosers */
    var updateToggable = function() {
      var scope = $(this).parents('.js-toggable-container')
      var selector = $('.js-toggable', scope);
      // TODO animate - this slideDown/Up currently doesn't work in IE8, though [thomas, 2011-03-29]
      if (this.checked) {
        selector.show();
      } else {
        selector.hide();
      }
    };

    var initToggable = function () {
      var scope = $(this).parents('.js-toggable-container')
      var selector = $('.js-toggable', scope);
      selector.toggle(this.checked);
    };

    $(".js-toggler").each(initToggable).click(updateToggable);

    /* initialize url selectors */
    $(".js-url-selector").change(function() {
      var selected = $(this).val()
      if (selected != '') {
        window.location.href = selected;
      }
    });

  });

})(jQuery);

