  //apply launch_video to all anchors with rel="video"
  $('a[rel="watch-video"]').each(function()
  {
    $(this).click(function()
    {
      var href = $(this).attr('href');
      // try and find width and height properties embedded in the url
      widthheight = href.match(/width=([0-9]+)&height=([0-9]+)$/);
      width = (href.match(/width=[0-9]+&height=[0-9]+$/) ? widthheight[1] : 320);
      height = (href.match(/width=[0-9]+&height=[0-9]+$/) ? widthheight[2] : 240);
      
      launch_video(href, width, height);
      return false;
    });
  });

launch_video = function( video_file, window_width, window_height ) {
  window.open( video_file, 'MAF_video', 'scrollbars=no,resizable=no,width=' + window_width + ',height=' + window_height );
};

$(document).ready(function()
{
  $('div.quiz a.answer').click(function(e)
  {
    e.preventDefault();
    
    $('.selected_answer').each(function()
    {
      $(this).removeClass('selected_answer');
      $(this).css('background-position', 'top');
    });
    $(this).addClass('selected_answer');
    $(this).css('background-position', 'bottom');
    $('div.quiz a.submit').removeClass('disabled');
    
    return false;
  });
  
  
  $('div.quiz a.submit').click(function(e)
  {
    e.preventDefault();
    
    $selected_answer = $('.selected_answer');
    if ( ! $selected_answer )
    {
      return false;
    }
    
    $('#quizPopup').load(
      $(this).attr('href') + '?mode=ajax',
      {
        question_order: $.fbmvc.question_order,
        answer: $selected_answer.children('.answer_key').html().toString()
      }
      );
    $('#quizPopup').show();
  });
  
  
  $('a.tell_a_friend').click(function(e)
  {
    var page_title = $('title').html().replace(/^([\x20-\xff]+) .*$/, '$1');
    var subject = page_title;
    var body = "I thought you might find the following page interesting:\n\n" +
      page_title + "\n" + 
      window.location + "\n\n";
    
    $(this).attr('href', 'mailto:?subject=' + subject.raw_url_encode() + '&body=' + body.raw_url_encode());
  });
  
  
});

