jQuery(document).ready(function($){

	$("ul.assessmentlist li").click(function() {
		parentID = $(this).parent().attr("id");
		questionAnswer = $(this).attr("rel");
		questionID = parseInt(onlyNumbers(parentID));
		currentQuestionID = questionID;
		llScoreList[questionID] = questionAnswer;
		$("ul#" + parentID + " li").removeClass("btnchecked");
		$(this).addClass("btnchecked");
	});
	$("#tooltip4").click(function() { $("#tooltip4").hide(); })


	var currentQuestionID = 0;
	var currentPosition = 0;
	var questionID = 0;
	var parentID = 0;
	var profiletype = "";
	var questionAnswer = "";
	var slideWidth = 936;
	var slides = $('.assessmentframe');
	var numberOfSlides = slides.length;
	slides.wrapAll('<div id="slideInner" class="clearfix"></div>').css({'float': 'left', 'width': slideWidth });
	$('#slideInner').css('width', slideWidth * numberOfSlides);

	//Initialize Profile Type
	profiletype = document.form1.profiletype.value;
	$(".assessmentlist li, .endtext").hide();
	$(".question-" + profiletype).show();

	if (profiletype == "teens") {
		$("#firstnext").hover(function() {
			$("#firsttooltip").show();
		},function() {
			$("#firsttooltip").hide();
		});
	}




	$('.control').click(function(){
		if ($(this).hasClass("evaluatequiz")) evaluateResults("quiz");
		if ($(this).hasClass("evaluateprofile")) evaluateResults("profile");
		if ($(this).hasClass("hidepeopleicon")) {
			$("#people").hide();
		} else {
			$("#people").show();
		}
		if ($(this).hasClass("fullstartover")) {
			currentPosition = 0;
			startover();
			$('#slideInner').css({ 'marginLeft': '0'});
		} else {
			requireCheck = true;
			if (requireCheck && $(this).hasClass("required") && !$("ul#list" + currentQuestionID + " li").hasClass("btnchecked")) {
				$("#tooltip4").show();
			} else {
				currentPosition = currentPosition + parseInt($(this).attr("rel"));
				if (currentQuestionID > 0) currentQuestionID = currentQuestionID + parseInt($(this).attr("rel"));
				$("#tooltip4").hide();
				$('#slideInner').animate({ 'marginLeft': slideWidth * (-currentPosition) }, 200);
			}
		}
		return false;
	});

	function startover() {
		$("ul.assessmentlist li").removeClass("btnchecked");
		for (i=1; i<=30; i++) {
			llScoreList[i] = "";
		}
		$(".score").html("0");
		$(".scorename").removeClass("purple");
		$("#resultstitle").html("");
		$("#resultstext").html("");
	}


	function evaluateResults(assessmentType) {
		var loveLanguage = 0;
		var maxNum = 0;
		if (assessmentType == "quiz") {
			for (i=1; i<=llScoreList.length; i++) {
				if (llScoreList[i] == "A") llScoreTotals[1]++;
				if (llScoreList[i] == "B") llScoreTotals[2]++;
				if (llScoreList[i] == "C") llScoreTotals[3]++;
				if (llScoreList[i] == "D") llScoreTotals[4]++;
				if (llScoreList[i] == "E") llScoreTotals[5]++;
			}
			for (i=1; i<=5; i++) {
				if (llScoreTotals[i] > maxNum) { loveLanguage = i; maxNum = llScoreTotals[i]; }
			}
			if (quiztype == "apology") {
				$("#resultstitle").html(apologyName[loveLanguage]);
				$("#resultstext").html(apologyDescription[loveLanguage]);
			} else {
				$("#resultstitle").html(llName[loveLanguage]);
				$("#resultstext").html(llDescription[loveLanguage]);
			}
			for (i=1; i<=5; i++) { llScoreTotals[i] = 0; }

		} else if (assessmentType == "profile") {
			for (i=1; i<=llScoreList.length; i++) {
				if (llScoreList[i] == "A") llScoreTotals[1]++;
				if (llScoreList[i] == "B") llScoreTotals[2]++;
				if (llScoreList[i] == "C") llScoreTotals[3]++;
				if (llScoreList[i] == "D") llScoreTotals[4]++;
				if (llScoreList[i] == "E") llScoreTotals[5]++;
			}
			for (i=1; i<=5; i++) {
				$(".score" + i + " .score").html(llScoreTotals[i]);
				if (llScoreTotals[i] > maxNum) { loveLanguage = i; maxNum = llScoreTotals[i]; }
			}
			$(".score" + loveLanguage + " .scorename").addClass("purple");
			
			var ChildName = "";
			lovelanguagename = llName[loveLanguage];
			if (profiletype == "apology") {
				$("#resultstitle").html(apologyName[loveLanguage]);
				$("#resultstext").html(apologyDescription[loveLanguage]);
				lovelanguagename = apologyName[loveLanguage];
			} else if (profiletype == "teens") {
				$("#resultstitle").html(llName[loveLanguage]);
				$("#resultstext").html(teensDescription[loveLanguage]);
			} else if (profiletype == "singles") {
				$("#resultstitle").html(llName[loveLanguage]);
				$("#resultstext").html(singlesDescription[loveLanguage]);
			} else if (profiletype == "children") {
				$("#resultstitle").html(llName[loveLanguage]);
				$("#resultstext").html(childrenDescription[loveLanguage]);
				ChildName = $("#childname").val();
			} else {
				$("#resultstitle").html(llName[loveLanguage]);
				$("#resultstext").html(llDescription[loveLanguage]);
			}
			
			//Send Email
			emailname = document.yourinfoform.name.value;
			emailaddress = document.yourinfoform.email.value;
			jQuery.get("/wp-content/themes/moody_1.0/formprofileemail.php", {
				source: "website",
				name: emailname,
				email: emailaddress,
				profiletype: profiletype,
				childname: ChildName,
				lovelanguage: lovelanguagename,
				llScoreNumber: loveLanguage,
				llScoreA: llScoreTotals[1],
				llScoreB: llScoreTotals[2],
				llScoreC: llScoreTotals[3],
				llScoreD: llScoreTotals[4],
				llScoreE: llScoreTotals[5]
			});
			for (i=1; i<=5; i++) { llScoreTotals[i] = 0; }
		}
	}

	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}

	function onlyNumbers(pstrSource) { var m_strOut = new String(pstrSource); m_strOut = m_strOut.replace(/[^0-9]/g, ''); return m_strOut; }

});



var llName = new Array(5);
llName[0] = "Whoops!";
llName[1] = "Words of Affirmation";
llName[2] = "Quality Time";
llName[3] = "Receiving Gifts";
llName[4] = "Acts of Service";
llName[5] = "Physical Touch";

var llDescription = new Array(5);
llDescription[0] = "<p>It looks like you might have missed a step. Please go back and make sure a box is checked.</p>";
llDescription[1] = "<p>Actions don&rsquo;t always speak louder than words. If this is your love language, unsolicited compliments mean the world to you. Hearing the words, &ldquo;I love you,&rdquo; are important&ndash;hearing the reasons behind that love sends your spirits skyward. Insults can leave you shattered and are not easily forgotten.</p>";
llDescription[2] = "<p>In the vernacular of Quality Time, nothing says, &ldquo;I love you,&rdquo; like full, undivided attention. Being there for this type of person is critical, but really being there&ndash;with the TV off, fork and knife down, and all chores and tasks on standby&ndash;makes your significant other feel truly special and loved. Distractions, postponed dates, or the failure to listen can be especially hurtful.</p>";
llDescription[3] = "<p>Don&rsquo;t mistake this love language for materialism; the receiver of gifts thrives on the love, thoughtfulness, and effort behind the gift. If you speak this language, the perfect gift or gesture shows that you are known, you are cared for, and you are prized above whatever was sacrificed to bring the gift to you. A missed birthday, anniversary, or a hasty, thoughtless gift would be disastrous&ndash;so would the absence of everyday gestures.</p>";
llDescription[4] = "<p>Can vacuuming the floors really be an expression of love? Absolutely! Anything you do to ease the burden of responsibilities weighing on an &ldquo;Acts of Service&rdquo; person will speak volumes. The words he or she most want to hear: &ldquo;Let me do that for you.&rdquo; Laziness, broken commitments, and making more work for them tell speakers of this language their feelings don&rsquo;t matter.</p>";
llDescription[5] = "<p>This language isn&rsquo;t all about the bedroom. A person whose primary language is Physical Touch is, not surprisingly, very touchy. Hugs, pats on the back, holding hands, and thoughtful touches on the arm, shoulder, or face&ndash;they can all be ways to show excitement, concern, care, and love. Physical presence and accessibility are crucial, while neglect or abuse can be unforgivable and destructive.</p>";

var teensDescription = new Array(5);
teensDescription[0] = "<p>It looks like you might have missed a step. Please go back and make sure a box is checked.</p>";
teensDescription[1] = "<p>Actions don&rsquo;t always speak louder than words. If this is your love language, unsolicited compliments mean the world to you. Hearing the words, &ldquo;I love you,&rdquo; are important&mdash;hearing the reasons behind that love sends your spirits skyward. Insults can leave you shattered and are not easily forgotten.</p>";
teensDescription[2] = "<p>In Quality Time, nothing says &ldquo;I love you&rdquo; like full, undivided attention. Being there for this type of person is critical, but really being there&mdash;with the TV off, fork and knife down, and all chores and tasks on standby&mdash;makes you feel truly special and loved. Distractions, postponed activities, or the failure to listen can be especially hurtful.</p>";
teensDescription[3] = "<p>Don&rsquo;t mistake this love language for materialism; the receiver of gifts thrives on the love, thoughtfulness, and effort behind the gift. If you speak this language, the perfect gift or gesture shows that you are known, you are cared for, and you are prized above whatever was sacrificed to bring the gift to you. A missed birthday or a hasty, thoughtless gift would be disastrous&mdash;so would the absence of everyday gestures.</p>";
teensDescription[4] = "<p>Can helping with homework really be an expression of love? Absolutely! Anything you do to ease the burden of responsibilities weighing on an &ldquo;Acts of Service&rdquo; person will speak volumes. The words he or she most wants to hear: &ldquo;Let me do that for you.&rdquo; Laziness, broken commitments, and making more work for them tell speakers of this language their feelings don&rsquo;t matter.</p>";
teensDescription[5] = "<p>A person whose primary language is Physical Touch is, not surprisingly, very touchy. Hugs, pats on the back, and thoughtful touches on the arm&mdash;they can all be ways to show excitement, concern, care, and love. Physical presence and accessibility are crucial, while neglect or abuse can be unforgivable and destructive.</p>";

var singlesDescription = new Array(5);
singlesDescription[0] = "<p>It looks like you might have missed a step. Please go back and make sure a box is checked.</p>";
singlesDescription[1] = "<p>Actions don&rsquo;t always speak louder than words. If this is your love language, unsolicited compliments mean the world to you. Hearing the words, &ldquo;I love you,&rdquo; are important&mdash;hearing the reasons behind that love sends your spirits skyward. Insults can leave you shattered and are not easily forgotten.</p>";
singlesDescription[2] = "<p>In Quality Time, nothing says &ldquo;I love you&rdquo; like full, undivided attention. Being there for this type of person is critical, but really being there&mdash;with the TV off, fork and knife down, and all chores and tasks on standby&mdash;makes you feel truly special and loved. Distractions, postponed activities, or the failure to listen can be especially hurtful.</p>";
singlesDescription[3] = "<p>Don&rsquo;t mistake this love language for materialism; the receiver of gifts thrives on the love, thoughtfulness, and effort behind the gift. If you speak this language, the perfect gift or gesture shows that you are known, you are cared for, and you are prized above whatever was sacrificed to bring the gift to you. A missed birthday or a hasty, thoughtless gift would be disastrous&mdash;so would the absence of everyday gestures.</p>";
singlesDescription[4] = "<p>Can helping with homework really be an expression of love? Absolutely! Anything you do to ease the burden of responsibilities weighing on an &ldquo;Acts of Service&rdquo; person will speak volumes. The words he or she most wants to hear: &ldquo;Let me do that for you.&rdquo; Laziness, broken commitments, and making more work for them tell speakers of this language their feelings don&rsquo;t matter.</p>";
singlesDescription[5] = "<p>A person whose primary language is Physical Touch is, not surprisingly, very touchy. Hugs, pats on the back, and thoughtful touches on the arm&mdash;they can all be ways to show excitement, concern, care, and love. Physical presence and accessibility are crucial, while neglect or abuse can be unforgivable and destructive.</p>";

var childrenDescription = new Array(5);
childrenDescription[0] = "<p>It looks like you might have missed a step. Please go back and make sure a box is checked.</p>";
childrenDescription[1] = "<p>People whose love language is words of affirmation like for others to use words to tell them that they are special and that they do a good job.</p>";
childrenDescription[2] = "<p>People with the love language of quality time like it when others do things with them like play a game, watch television, or go to a ballgame.</p>";
childrenDescription[3] = "<p>People with the love language of gifts feel good when someone gives them a special present or surprise.</p>";
childrenDescription[4] = "<p>A person whose love language is acts of service likes it when others do nice things for them such as helping with chores, helping with school projects, or driving them places. </p>";
childrenDescription[5] = "<p>People whose love language is physical touch like to receive hugs, kisses, and high-fives.</p>";

var apologyName = new Array(5);
apologyName[0] = "Whoops!";
apologyName[1] = "Expressing Regret";
apologyName[2] = "Accepting Responsibility";
apologyName[3] = "Making Restitution";
apologyName[4] = "Genuinely Repenting";
apologyName[5] = "Requesting Apology";

var apologyDescription = new Array(5);
apologyDescription[0] = "<p>It looks like you might have missed a step. Please go back and make sure a box is checked.</p>";
apologyDescription[1] = "<p>You have chosen Expressing Regret as your primary Apology Language. What you want to hear in an apology is an immediate expression of sorrow for causing you pain. A simple &ldquo;I&rsquo;m sorry&rdquo; goes a long way.</p>";
apologyDescription[2] = "<p>You have chosen Accepting Responsibility as your primary Apology Language. What you are looking for in an apology is maturity. You most want to hear the offending party say, I was wrong and I take responsibility for my actions.</p>";
apologyDescription[3] = "<p>You have chosen Making Restitution as your primary Apology Language. You find it easiest to forgive when action is taken to compensate for the wrong done to you. You listen not only to admission of fault, but also for the question, What can I do to make it better?</p>";
apologyDescription[4] = "<p>You have chosen Genuinely Repenting as your primary Apology Language. You are most able to forgive someone who offends you when they are willing to change in order to avoid hurting you again.</p>";
apologyDescription[5] = "<p>You have chosen Requesting Apology as your primary Apology Language. You want to know that the offending person highly values your relationship and sincerely desires restoration.</p>";

var llScore = new Array(5);
llScore[1] = 0;
llScore[2] = 0;
llScore[3] = 0;
llScore[4] = 0;
llScore[5] = 0;

var llScoreList = new Array(30);
llScoreList[1] = "";
llScoreList[2] = "";
llScoreList[3] = "";
llScoreList[4] = "";
llScoreList[5] = "";
llScoreList[6] = "";
llScoreList[7] = "";
llScoreList[8] = "";
llScoreList[9] = "";
llScoreList[10] = "";
llScoreList[11] = "";
llScoreList[12] = "";
llScoreList[13] = "";
llScoreList[14] = "";
llScoreList[15] = "";
llScoreList[16] = "";
llScoreList[17] = "";
llScoreList[18] = "";
llScoreList[19] = "";
llScoreList[20] = "";
llScoreList[21] = "";
llScoreList[22] = "";
llScoreList[23] = "";
llScoreList[24] = "";
llScoreList[25] = "";
llScoreList[26] = "";
llScoreList[27] = "";
llScoreList[28] = "";
llScoreList[29] = "";
llScoreList[30] = "";

var llScoreTotals = new Array(5);
llScoreTotals[1] = 0;
llScoreTotals[2] = 0;
llScoreTotals[3] = 0;
llScoreTotals[4] = 0;
llScoreTotals[5] = 0;

