//reveals and hides answers
var expand_img = 'tpl/img/expand.gif';
var collapse_img = 'tpl/img/collapse.gif';

$(document).ready(function() {
  $('#q-and-a li').each(function() {
    $(this).addClass('collapsed');
    //hide answers
    $(this).children('.answer').hide();
    //reformat answers
    $(this).children('.answer').css('padding-left', '20px');
    //reformat questions
    $(this).children('.question').css({
      'background' : 'transparent url(' + expand_img + ') scroll no-repeat left 5px',
      'padding-left' : '20px',
      'font-weight' : 'normal',
      'color' : '#c55530',
      'cursor' : 'pointer'
    });
  });
  $('#q-and-a li.collapsed .question').mouseover(function() {
    $(this).css('color', '#333');
  });
  $('#q-and-a li.collapsed .question').mouseout(function() {
    $(this).css('color', '#c55530');
  });
  $('#q-and-a li .question').click(function() {
    if ($(this).parents('li').hasClass('collapsed')) {
      $(this).siblings('.answer').show('fast');
      $(this).parents('li').removeClass('collapsed');
      $(this).parents('li').addClass('expanded');
      $(this).css({
        'background-image' : 'url(' + collapse_img + ')',
        'font-weight' : 'bold',
        'color' : '#333'
      });
      $(this).mouseout(function() {
        $(this).css('color', '#333');
      });
    }
    else {
      $(this).siblings('.answer').hide('fast');
      $(this).parents('li').addClass('collapsed');
      $(this).parents('li').removeClass('expanded');
      $(this).css({
        'background-image' : 'url(' + expand_img + ')',
        'font-weight' : 'normal'
// we don't need to change the color back, because that's handled by the mouseout
//        'color' : '#c55530'
      });
      $(this).mouseout(function() {
        $(this).css('color', '#c55530');
      });
    }
  });
});
