$(document).ready(function() {
  var properties = {
    max_height: 44,
    fx_length: 500
  };

  $('[class^=center_balloon]').each(function() {
    var ch = $(this).find('div');

    var ch_id = ch.attr('id');
    var ch_old_height = ch.height();
    if (typeof(ch_id) === "string")
    {
      ch_id = parseInt(ch_id.replace('question_', ''));
      var ch = $('#question_' + ch_id);
      var toggle_status = false;
      var toggle = $('#toggle_' + ch_id);

      if (ch.height() > properties.max_height)
      {
        ch.css({
          overflow: 'hidden',
          height: properties.max_height
        });

      toggle.css({
        display: 'block'
      });
      }

      toggle.click(function() {
        if (toggle_status)
        {
          ch.animate({
            height: properties.max_height
          }, properties.fx_length);

          toggle.html('Toon volledig bericht');
          toggle_status = false;
        }
        else
        {
          ch.animate({
            height: ch_old_height
          }, properties.fx_length);

          toggle.html('Verberg volledig bericht');
          toggle_status = true;
        }

        $('html,body').animate({scrollTop: (ch.offset().top - 40)}, properties.fx_length);
      });
    }
  });
});