jQuery(document).ready(function($) {
  
  showMarkup = '<span class="question-toggle show"><span>[+]</span></span>';
  hideMarkup = '<span class="question-toggle show"><span>[&ndash;]</span></span>';

  questions = $('.faq-question');

  answers = $('.faq-answer');
  $(answers).hide();  

  $(questions).click(toggleAnswers);
  
  showAllButton = $('.faq-show-all');
  hideAllButton = $('.faq-hide-all');
  
  $(showAllButton).click(showAllAnswers);
  $(hideAllButton).click(hideAllAnswers);
});

jQuery(document).ready(function($){

  $('a.video-player').flowplayer("flowplayer/flowplayer.3.1.4.swf");
  player = flowplayer();
  
  $('.faq-show-all, .faq-hide-all').click(function() {
      $f("*").each(function() {
        this.unload();
      });
  });

});

jQuery(document).ready(function($){
  hash_id = '';
  var hash_id = '#' + $.param.fragment();
  $(hash_id).click();
});

function toggleAnswers()
{
  var question = $(this);
  var answer   = $(question).next('.faq-answer');
  var toggle   = $(question).find('.question-toggle')
  
  var video_id = $(answer).attr('rel');
  
  if( $(answer).is(':hidden') )
  { 
    $f(video_id).load();
    $(answer).slideDown(500);
    $(toggle).replaceWith(hideMarkup);
  } else {
    $f(video_id).unload();
    $(answer).slideUp(500);
    $(toggle).replaceWith(showMarkup);
  }
  
  $(showAllButton).removeClass('faq-show-all-active');
  $(hideAllButton).removeClass('faq-hide-all-active');
}

function hideAllAnswers()
{
  $(hideAllButton).addClass('faq-hide-all-active');
  $(showAllButton).removeClass('faq-show-all-active');
  
  $(answers).slideUp('fast');
  $.each($('.question-toggle'), function() {
    $(this).replaceWith(showMarkup);
  });

}

function showAllAnswers()
{
  $(showAllButton).addClass('faq-show-all-active');
  $(hideAllButton).removeClass('faq-hide-all-active');
  
  $(answers).slideDown('fast');
  $.each($('.question-toggle'), function() {
    $(this).replaceWith(hideMarkup);
  });

}
