$(document).ready(function(){ 
	
	//PNG FIX
	$(document).pngFix();			


	
	
	//BUTTON ROLLOVERS
	$('img.rollover').hover(
    function() {
        //over
        var newImage = $(this).attr('src').replace('-out', '-ovr');
        $(this).attr('src', newImage);
    },
    function() {
        //out
        var newImage = $(this).attr('src').replace('-ovr', '-out');
        $(this).attr('src', newImage);
    }
	);
	

	
	

	//SEARCH - CLEAR INPUT
	$('.clearInput').each(function() {
		var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});


	
	

	//IE6 BUG FIX FOR FOCUS STATE ON MEGA MENU
	$('#mainnav_newborns .sub').hover(function(){
		   $('#mainnav_newborns a').addClass('highlight');
	}, function() {
		   $('#mainnav_newborns a').removeClass('highlight');
	});
	
	$('#mainnav_infants .sub').hover(function(){
		   $('#mainnav_infants a').addClass('highlight');
	}, function() {
		   $('#mainnav_infants a').removeClass('highlight');
	});
	
	$('#mainnav_toddlers .sub').hover(function(){
		   $('#mainnav_toddlers a').addClass('highlight');
	}, function() {
		   $('#mainnav_toddlers a').removeClass('highlight');
	});
	$('#mainnav_feeding_solutions .sub').hover(function(){
		   $('#mainnav_feeding_solutions a').addClass('highlight');
	}, function() {
		   $('#mainnav_feeding_solutions a').removeClass('highlight');
	});



	//TOGGLE PLUS/MINUS
	//EXPAND COLLAPSE
	$(".toggle_container").hide();
	
	$("h2.expand_heading").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	
	$("h2.expand_heading_open").toggle(function(){
		 $(this).removeClass("active");
		}, function () {
		
		$(this).addClass("active");
	});
	
	$("h2.expand_heading").click(function(){
		$(this).next(".toggle_container").slideToggle("slow");
	});
	$("h2.expand_heading_open").click(function(){
		$(this).next(".toggle_container").slideToggle("slow");
	});
	
	// paragraph expansions
	$("p.expand_heading").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	
	$("p.expand_heading_open").toggle(function(){
		 $(this).removeClass("active");
		}, function () {
		
		$(this).addClass("active");
	});
	
	$("p.expand_heading").click(function(){
		$(this).next(".toggle_container").slideToggle("slow");
	});
	$("p.expand_heading_open").click(function(){
		$(this).next(".toggle_container").slideToggle("slow");
	});
	
	/*
	$(".expand_all").toggle(function(){
		$(this).addClass("expanded"); 
		}, function () {
		$(this).removeClass("expanded");
	});
	$(".expand_all").click(function(){
		$(".toggle_container").slideToggle("slow");
	});
	*/
	
	//Default Open Container
	$(".open").slideToggle("slow");
	
	
	//NEW REGISTRATION
	
	// Automatically activate questions if checkboxes are checked on page load
	if ($('#toggleElement').is(':checked')) {
		$('.timeline_month :input').removeAttr('disabled');
		$('.timeline_container').removeClass('timeline_disabled');
		$('.expecting_container #toggleP').removeClass('duedate_disabled');
		$('.relationship_container').removeClass('relationship_disabled');
		$('.relationship_container :input').removeAttr('disabled');
	}
	if ($('#toggleElement2').is(':checked')) {
		$('.birthdate_container :input').removeAttr('disabled');
		$('.birthdate_container :input').removeClass('select_disabled');
		$('.birthdate_container #toggleLabel2').removeClass('label_disabled');
		$('.relationship_container').removeClass('relationship_disabled');
		$('.relationship_container :input').removeAttr('disabled');
	}
   
   // I am Expecting
   $('#toggleElement').click(function() {
		if ($('#toggleElement').is(':checked')) {
			$('.timeline_month :input').removeAttr('disabled');
			$('.timeline_container').removeClass('timeline_disabled');
			$('.expecting_container #toggleP').removeClass('duedate_disabled');
		} else {
			$('.timeline_month :input').attr('disabled', true);
			$('.timeline_month :input').attr('checked', false);
			$('.timeline_container').addClass('timeline_disabled');
			$('.expecting_container #toggleP').addClass('duedate_disabled');
			$('.expecting_container .form_error').addClass('hide');
		}   
	});
   
   // I already have a child
	$('#toggleElement2').click(function() {
		if ($('#toggleElement2').is(':checked')) {
			$('.birthdate_container :input').removeAttr('disabled');
			$('.birthdate_container :input').removeClass('select_disabled');
			$('.birthdate_container #toggleLabel2').removeClass('label_disabled');
		} else {
			$('.birthdate_container :input').attr('disabled', true);
			$('.birthdate_container :input').attr('selectedIndex', 0);
			$('.birthdate_container :input').addClass('select_disabled');
			$('.birthdate_container #toggleLabel2').addClass('label_disabled');
			$('.birthdate_container .form_error').addClass('hide');
		}   
	});
	
	// Relationship quesiton activate/deactivate
	$('#toggleElement').click(function() {
		
		if ($('#toggleElement:checked').val() == null && $('#toggleElement2:checked').val() == null) {
			$('.relationship_container').addClass('relationship_disabled');
			$('.relationship_container :input').attr('disabled', true);
			$('.relationship_container :input').attr('checked', false);
			$('.relationship_container .form_error').addClass('hide');
		} else {
			$('.relationship_container').removeClass('relationship_disabled');
			$('.relationship_container :input').removeAttr('disabled');
		}   
		
	});
	$('#toggleElement2').click(function() {
		
		if ($('#toggleElement:checked').val() == null && $('#toggleElement2:checked').val() == null) {
			$('.relationship_container').addClass('relationship_disabled');
			$('.relationship_container :input').attr('disabled', true);
			$('.relationship_container :input').attr('checked', false);
			$('.relationship_container .form_error').addClass('hide');
		} else {
			$('.relationship_container').removeClass('relationship_disabled');
			$('.relationship_container :input').removeAttr('disabled');
		}   
		
	});
	
	//Show tooltip on submit button based on items checked		
	$(".newreg_submit").mouseover(function() {
	//if($('input[name=duedate]:checked').val() == null && ($('#birthDateMo').val() == '' || $('#birthDateDay').val() == '' || $('#birthDateYear').val() == '')) {
		//$(this).next('.newreg_submit_tooltip').css('display', 'block');
	//}
	if ($('#toggleElement:checked').val() == null && $('#toggleElement2:checked').val() == null) {
		$(this).next('.newreg_submit_tooltip').css('display', 'block');
	}
	}).mouseout(function(){
		$(this).next('.newreg_submit_tooltip').css('display', 'none');
	});
	
	//Form Error
	if ($('.form_error').is(':visible')) {
		$('.form_error').prev().addClass('red');
	} else {
		$('.form_error').prev().removeClass('red');
	}
	
	
	$(".question").mouseover(function() {
		$(this).next('.question_tooltip').css('display', 'block');
	}).mouseout(function(){
		$(this).next('.question_tooltip').css('display', 'none');
	});
	
	if ($('.form_error').is(':visible')) {
		$('.form_error').prev().addClass('red');

	} else {
		$('.form_error').prev().removeClass('red');
	}
	
	//END NEW REGISTRATION
	
	
}); 

