jQuery(document).ready(function(){
	jQuery('#nav-search a').click(function(){
		jQuery('#search-container').show();
		jQuery('#nav-store').css("background-image", "none"); 		
		jQuery('#search-q').focus();
		return false;
	});
	jQuery('#button-search-close').click(function(){
		jQuery('#search-container').hide();
		jQuery('#nav-store').css("background-image", "url(/wp-content/themes/vitaminseo/images/baby-store-icon.png)"); 
	});
	
	// if the function argument is given to overlay,
	// it is assumed to be the onBeforeLoad event listener
	jQuery("a.business-contact-pop").overlay({
		effect: 'apple',
		onBeforeLoad: function() {
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");
			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"));
		}
	});	

  //check if the radio button is not ticked, then disable the submit button 
  if ( ! jQuery("input").is(':checked') ) {
    jQuery("input[type=Submit]").attr("disabled","disabled");
  } else { 
    jQuery("input[type=Submit]").removeAttr("disabled");
  };
  
  //if the option changes its event/status then remove the attr that disables the button 
  jQuery("input[type=radio]").change(function() {
    jQuery("input[type=Submit]").removeAttr("disabled");
  });
  
  //at the last pregnancy quiz question (question 15), fade the reminder in
  jQuery('.reminder').fadeIn('slow', function() {
    // Animation complete
  });
	
});

function dateChecker(whichform) {
	var wbwbottom = '';
	if (whichform == 'bottom') { wbwbottom = 1; }
	if (whichform == 'popover') { wbwbottom = 2; }
	var wbwName = jQuery('#wbwname'+wbwbottom).val();	
	if (wbwName == '') { return false;  }
	if (wbwName == 'First Name') { return false;  }	
	var wbwfrom = jQuery('#wbwfrom'+wbwbottom).val();
	if (wbwfrom == '') { return false;  }
	if (wbwfrom == 'email@address.com') { return false;  }		
	var dueMonth = jQuery('#preg-month'+wbwbottom).val();
	if (dueMonth == 'mm') { return false;  }
	var dueDay = jQuery('#preg-day'+wbwbottom).val();
	if (dueDay == 'dd') {  return false; }	
	var dueYear = jQuery('#preg-year'+wbwbottom).val();
	if (dueYear == 'yyyy') { return false; }	
	var dueMonth = dueMonth-1;
	var today=new Date();
	var dueDate=new Date(dueYear, dueMonth, dueDay);
	var one_week=1000*60*60*24*7;
	var weeksDueDate = (Math.ceil(39-(dueDate.getTime()-today.getTime())/(one_week)));
	if ((weeksDueDate > 0) && (weeksDueDate < 41)) {
		jQuery('[name=meta_message]').val(weeksDueDate);
	} else {
		jQuery('#wbw-msg'+wbwbottom).text('Sorry dates you have entered don\'t appear to be quite right.');	
		doBGFade( jQuery("#wbw-msg"+wbwbottom),'purple');
		return false;
	}
}

// function easeInOut
// function doBGFade
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr){var delta=maxValue-minValue;var stepp=minValue+(Math.pow(((1/totalSteps)*actualStep),powr)*delta);return Math.ceil(stepp)}function doBGFade(elem,fadeColour){if(fadeColour=='yellow'){var startRGB=[235,216,249]}else{var startRGB=[255,243,111]}var endRGB=[255,255,255];var finalColor='transparent';var steps=75;var intervals=20;var powr=4;if(elem.bgFadeInt)window.clearInterval(elem.bgFadeInt);var actStep=0;elem.bgFadeInt=window.setInterval(function(){elem.css("backgroundColor","rgb("+easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")");actStep++;if(actStep>steps){elem.css("backgroundColor",finalColor);window.clearInterval(elem.bgFadeInt)}},intervals)}


