$(function() {

	$("button[name=sendSplash]", "body.js").hide();
	var circles = $("#circle1, #circle2, #circle3", "body.js");

	circles.hover(function() {
		$(this).addClass("over");
		$(this).find("ul").filter(':not(:animated)').slideDown(300);
	}, function() {
		$(this).removeClass("over");
		$(this).find("ul").fadeOut(150);
	});

	$(".selectedItem", circles).mouseenter(function() {
		$(this).prev().filter(':not(:animated)').slideDown(300);
	});

	$("ul", circles).mouseleave(function() {
		$(this).fadeOut(150);
	});

	var splashA = $("ul a", "#splash");
	var splashC = $("input[type=checkbox]", "#splash");
	var continueBtn = $("a#continueBtn", "#splash");

	splashA.bind("click", function(event) {

		event.preventDefault();
		var selectedAnchor = $(this).attr("rel");
		var selectedAnchorTxt;

		if (selectedAnchor != 0) {
			selectedAnchorTxt = $(this).text().substr(9);
		} else {
			selectedAnchorTxt = $(this).text();
		}

		$(this).blur().closest("ul").prev().val(selectedAnchor);
		$(this).closest("ul").next().find("strong").hide();
		$(this).closest("ul").next().find("strong.selectedText" + selectedAnchor).show();
		$(this).closest("ul").fadeOut(150);

		checkHpSelect(continueBtn);

	});

	$("#continueBtn").click(function (e) {
		e.preventDefault();
	});

	checkHpSelect(continueBtn);
	
	/*
	$(".overlay").height($('#pageWrap').height()).css({opacity: 0.7});
	$('#interstitial .overlay, #interstitial button.close, #interstitial a').click(function(){
		var lang = $('meta[name="language"]').attr('content');
		$('#interstitial').addClass('hide');
		setCookie('interstitial', 1, 31);
		//return false;
	});
	*/
});

function checkHpSelect (continueBtn) {
	var select1val = $("#childAge", "#circle1").val();
	var select2val = $("#feed", "#circle2").val();
	var select3val = $("#allergy", "#circle3").val();
	var out1, out2 = false;

	if (select1val != "-") {
		$(".selectedItem strong", "#circle1").hide();
		$(".selectedItem > .selectedText" + select1val, "#circle1").show();
		out1 = true;
	}

	if (select2val != "-") {
		$(".selectedItem strong", "#circle2").hide();
		$(".selectedItem > .selectedText" + select2val, "#circle2").show();
		out2 = true;
	}

	if (select3val != "-") {
		$(".selectedItem strong", "#circle3").hide();
		$(".selectedItem > .selectedText" + select3val, "#circle3").show();
	}

	if (out1 && out2) {
		continueBtn[0].className = "btnContinue";
		$('.btnContinue').click(function () {
			location.href = $('#splash').attr('action') + '?' + $('#splash').serialize();
		});
	}
}

function checkHpValue () {
	var input1val = $("input#allergy1", "#checkboxAllergy")[0].checked;
	var input2val = $("input#allergy2", "#checkboxAllergy")[0].checked;
	var selectedTextP = $(".selectedItem", "#circle3");

	$("strong", selectedTextP).hide();

	if (input1val && input2val) {
		$(".selectedText2", selectedTextP).show();
		$(".selectedText2 .cufon:not(:first)", selectedTextP).css({marginTop:"-4px"});
	} else if (input1val) {
		$(".selectedText0", selectedTextP).show();
	} else if (input2val) {
		$(".selectedText1", selectedTextP).show();
	} else {
		$(".selectedText", selectedTextP).show();
	}

}

