// Assign Fancyboxes to relevant anchors:
$(document).ready(function() {

  $(".sign-up .form_button").click(function(){
	 $(this).hide();
	 $(".processing_button").show();
	});
	
  $("a.lesson_end").fancybox({
    'autoDimensions'  : false,
    //'height'        : '50',
    //'width'        : 640,
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'speedIn'   : 600,
    'speedOut'    : 200,
    'overlayShow' : true,
		'overlayColor': '#000',
    'hideOnOverlayClick' : true,
    'titleShow' : false,
    'modal' : true,
    onStart: function(){
      $('#fancybox-outer').addClass($('#main').attr('class'));
    },
    onComplete: function() {
      /* Added a manual click listener to close the popup if the overlay is clicked
       * the default hideOnOverlayClick even was not working on the fancybox options.*/
      $('#fancybox-overlay').click(function(){$("#close_button").click()});
    }
  });

	$("a.login_fancybox").fancybox({
    'autoDimensions' : false,
    'height'        : 250,
    'width'        : 582,
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	true,
		'overlayColor': '#000',
		'hideOnOverlayClick' : true,
    'titleShow' : false,
		'modal' : true,
		onStart: function(){
			$('#fancybox-outer').addClass('red');
		},
    onComplete: function() {
			$('#login_email_address').focus();

      /* Added a manual click listener to close the popup if the overlay is clicked
       * the default hideOnOverlayClick even was not working on the fancybox options.*/
			$('#fancybox-overlay').click(function(){$("#close_button").click()});
		}
	});

  $("a.ask_a_question_fancybox").fancybox({
    'autoDimensions' : false,
    'height'        : 300,
    'width'        : 600,
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	true,
		'overlayColor': '#000',
		'hideOnOverlayClick' : true,
		'titleShow' : false,
    'modal' : true,
    onStart: function() {
		  /* This adds the main div's class to the fancybox outer.
		   * Creates an effect where the popups background is the same as the main contents background. */
		  $('#fancybox-outer').addClass($('#main').attr('class'));

      if ( $("#ask_a_question_flash").css("display") != 'none' ) {
        $("#ask_a_question_flash").hide();
      }

      if ($("#ask_a_question_flash").css("display") == 'none') {
        $("#ask_a_question_notice").show();
      }

      if ($("#ask_a_question_flash").css("display") == 'none') {
        $("#ask_a_question_fieldset").show();
      }

      if ($("#ask_a_question_flash").css("display") == 'none') {
        $("#ask_a_question_submit").show();
      }
    },
    onComplete: function() {
		  $('#ask_a_question_question').focus();

			/* Added a manual click listener to close the popup if the overlay is clicked
			 * the default hideOnOverlayClick even was not working on the fancybox options.*/
			$('#fancybox-overlay').click(function(){$("#close_button").click()});
		}
	});

});

function login_forgot_password() {
  if ($('#login_flash_notice').css('display') != 'none') {
    $('#login_flash_notice').hide('blind', null, 'fast');
  }
  $('#login_enter_password_notice').hide('blind',null, 'fast');
	$('#password_label').hide('blind',null,'fast');
  $('#login_password_input').hide('blind',null, 'fast');

  $('#login_submit').hide(
    'blind', null, 'fast',
    function(){
      $('#login_forgot_password_notice').show('blind', null, 'fast');
      $('#login_forgot_submit').show('blind', null, 'fast');
    }
  );
}

function login_remember() {
  if ($('#login_flash_notice').css('display') != 'none') {
    $('#login_flash_notice').hide('blind',null, 'fast');
  }
  $('#login_forgot_password_notice').hide('blind',null, 'fast');
  
  $('#login_password_input').show('blind',null, 'fast');
	$('#password_label').show('blind',null,'fast');

	
  $('#login_forgot_submit').hide(
    'blind', null, 'fast',
    function(){
      $('#login_enter_password_notice').show('blind',null, 'fast');
      $('#login_password').show('blind',null, 'fast');
	    $('#login_submit').show('blind',null, 'fast');
    }
  );
}

function login_submit_fix(submit_button) {
  // This fixes a weirdo annoying bug in form_to_remote that causes the first submit button to serialize each time.
  $('#login_commit').val(submit_button);
}

function missing_answers(num_questions){
  for(n=0;n<num_questions;n++){
     if($('input[name=questions['+n+']]:checked').val() == null) { return 1 };
  }
  return 0;
}

