var totalAs = 0;
var totalBs = 0;
var totalCs = 0;
var totalDs = 0;
var currentValue =0;

	function hideAnswer(){
						jQuery(".answer").removeClass("show").addClass("hide");
	}
	
jQuery(document).ready( function() {
								   hideAnswer();

});

function tallyLetters(currentName){
	currentObject = document.getElementsByName(currentName);
			for (index=0; index < currentObject.length; index++) {
				if (currentObject[index].checked) {
					var currentValue = currentObject[index].value;
					break;
				}
			}
// currentValue = document.getElementsByName(currentName).value;
	//alert(currentValue);
	 if(currentValue=="a"){totalAs += 1}
	 	 if(currentValue=="b"){totalBs += 1}
	 if(currentValue=="c"){totalCs += 1}
	 if(currentValue=="d"){totalDs += 1}
	}
	

var showSpeed =1000;

function showProduct(product){
	resetProductDisplay();
	jQuery(product).removeClass("hide").addClass("show");
	jQuery(product+" img").css("display", "block");
		jQuery(product+" h3").css("display", "block");
	jQuery(product).animate({opacity: 0},0).animate({opacity: 1},showSpeed);
	
	}

function resetProductDisplay(){
	jQuery("#quiz-answers a").each(function(){
		jQuery(this).removeClass("show").addClass("hide");}
	);
	
	
	}

function compareLetters(){
			//alert("error:totalAs="+ totalAs+", totalBs="+ totalBs+", totalCs="+ totalCs+", totalDs="+totalDs);

	 if(totalAs >=3 && totalBs !=3 && totalDs !=3 && totalCs !=3){
			 		// alert('a english lavender');
		
		showProduct("#english-lavender");
	} else if(totalBs >=3 && totalCs !=3 && totalDs !=3 && totalAs !=3){
		showProduct("#lemon-verbena");
	} else if(totalCs >=3 && totalBs !=3 && totalDs !=3 && totalAs !=3 ){
					//	 alert("C oatmeal almond");

		showProduct("#oatmeal-almond");

	} else if(totalDs >=3 && totalBs !=3 && totalCs !=3 && totalAs !=3){
		//pomegranate rose
										// alert("D pome rose");  
		showProduct("#pomegranate-rose");
	}
	else if(totalAs ==2 && totalBs ==2 && totalDs ==2){
		 //aloe cucumber
		showProduct("#aloe-cucumber");
	}
	 else if(totalAs ==2 && totalBs ==2 && totalCs ==2){
			 		 //alert('error:a b c split english lavender');
		showProduct("#english-lavender");
	 }
	  else if(totalAs ==2 && totalCs ==2 && totalDs ==2){
		 //alert("a c d split honeysuckle citrus");
		showProduct("#honeysuckle-citrus");
	}
	 else if(totalBs ==2 && totalCs ==2 && totalDs ==2){
		// alert("b c d split almond milk");
		showProduct("#almond-milk");
	}
	  else if(totalAs >=2 && totalBs >=2 && totalCs !=2 && totalDs !=2){
		 //alert("a b split honeysuckle citrus");
		showProduct("#honeysuckle-citrus");
	} 
	
	
	
	else if(totalAs >=2 && totalBs !=2 && totalCs >=2 &&totalDs !=2){
		//lavender wisteria
				 //alert("a c split lavender wisteria");
		showProduct("#lavender-wisteria");
	}
	
	 else if(totalAs >=2 && totalDs >=2){
		//pomegranate rose
				// alert("a d split pome rose");
		showProduct("#pomegranate-rose");
	} else if(totalBs >=2 && totalCs >=2){
		//oatmeal almond
						// alert("b c split oatmeal almond");

		 showProduct("#oatmeal-almond");
	} else if(totalBs >=2 && totalDs >=2){
		//aloe cucumber
		 showProduct("#aloe-cucumber");
	} else if(totalCs >=2 && totalDs >=2 && totalBs !=2 && totalAs !=2){
				// alert("c d split cocoa butter");
		showProduct("#cocoa-butter");
	} 
	
		
	
	
	else 
	{
		//alert("error:totalAs="+ totalAs+", totalBs="+ totalBs+", totalCs="+ totalCs+", totalDs="+totalDs);
	}
	
	
	
}


jQuery(function(){

	
	//alert("works");
	 jQuery("#form").submit(function(e) { 
	 	totalAs = 0;
	 totalBs = 0;
	 totalCs = 0;
	 totalDs = 0;
	 currentValue =0;
    if(jQuery('input[type=radio]:checked').length < 6) {
        //stop the form from submitting
        e.preventDefault();
        alert("Error: Please answer all of the questions");
		return false;
    }
tallyLetters("fragrance");
		tallyLetters("personality");
	tallyLetters("vacation");
	tallyLetters("color");
	tallyLetters("job");
	tallyLetters("perfume");
compareLetters();
    return false;
});
});

