$(document).ready(function(){
  /* make sure the right column bg doesn't cut off in the midst of a pipe */
  height_repeat = 200;
  current_height = $('#side_column_inner').height();
  round_up_height = (Math.ceil(current_height / height_repeat)) * height_repeat;
  $('#side_column_inner').height(Math.max(current_height, round_up_height + 55));
  /* make sure the make sure the main column is at least as tall as the right column */
  if ($('#main_column_inner').height() < $('#side_column_inner').height()) {
    $('#main_column_inner').height($('#side_column_inner').height());
  }

  /* add a hover class to hoverable items */
  $('.hoverable, .fancy-button').hover(
    function () { 
      $(this).addClass('hover');
      if ($(this).hasClass('rounded_by_jQuery_corners')) {
        $(this).corners();
      }
    },
    function () { 
      $(this).removeClass('hover');
    }
  );


  /* expand form sections */
  var trans = (jQuery.browser.msie) ? 'transparent' : '';
  $('.expander').corners(trans);
  $('.expander h3').click(function () {
    $(this).parent().toggleClass('active');
    $(this).next().toggle();
    $(this).find('.expand').toggle();
  }).css({'cursor': 'pointer'})
    .append('<span class="expand">Expand</span>')
    .next().addClass('expander-content')
    .append('<div class="controls"><a href="#" class="minimize">Minimize</a></div>');
  $('.expander.removable .controls').prepend('<a href="#" class="remove">Remove</a>');
  $('.expander .expand').click(function(event){
    event.preventDefault();
  });
  
  $('.expander .controls .minimize').click(function(){
    $(this).parent().parent().parent().find('h3').trigger('click');
  });
  
  $('.expander .controls .remove').click(function(){
    $(this).parents('.expander').remove();
  });

  
  /* tooltips for help text */
  $('.tooltip').bt({
    //trigger: 'click',
    cornerRadius: 0,
    fill: '#ECF7FF',
    spikeGirth: 6,
    spikeLength: 6,
    strokeWidth: 1,
    strokeStyle: '#9FD7FF',
    positions: ['right', 'top', 'bottom', 'left']
  });
  
  /* discussion */
  $('#quote_discussion .message').each(style_discussion_message);
  $('#quote_discussion textarea').resizable({handles:'s'});
})

function style_discussion_message() {
  $(this).corners().append('<div class="speech-tail"/>');
  // seems like you can't pass in a bg color to .corners(), so we fake it out
  var bg = $(this).css('background-color');
  $(this).css('background', '#fff');
  $(this).find('h4').corners('top');
  $(this).css('background', bg);
}
