$(document).ready(function(){

  var facts_container = $('.facts_container div');
  var fact_count = facts_container.size();
  var new_index = _random(fact_count);
  var prev_fact = facts_container.eq(new_index);
  prev_fact.show();
  $('.fact_switch').click(function(){
    new_index = _random(fact_count);

    prev_fact.fadeOut(300, function(){
      prev_fact = facts_container.eq(new_index);
      prev_fact.fadeIn(300);
    });
  });

  $('#question_form').each(function(){
    scroll_to_form();
    $('#flash_notice').each(function(){
      $('#form_block').hide();
      $('#one_more_message').click(function(){
        $('#flash_notice').hide();
        $('#form_block').show();
      });
    });
  });
    
  $('#scroll_to_form').click(function(){scroll_to_form();});

  $('.center_list tr:not(.region)').hover(
    function(){ $(this).addClass('hover')},
    function(){ $(this).removeClass('hover')}
  );

  $('form .submit').click(function(){
    $(this).parents('form').eq(0).submit();
  });

});


_random = function(b) {
  return Math.floor(b*Math.random());
}

function scroll_to_form() {
  var destination = $('#form_block').offset().top;
  $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
}
