$(document).ready (function()
{
  
  // show all classes if javascript enabled
  $(".noshow").show();
  
  //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;
    });
  });
  
  //for /about-maf/our-scientists/ page, bind a change event to grab ajax
  $("#select_profile").bind("change", function(e)
  {
    if ($(this).val() != '')
    jQuery.get(
      "/about-maf/our-scientists/" + $(this).val() + "/?mode=ajax&request=scientist-profile",
       function(results)
       {
         $('#profile_info').html(results);
       }
    );
  });
  
  $('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());
  });
  
  $('input#submit_profile').hide();


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 );
  
};

});
