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");
	});


	var currentQuestionID = 0;
	var currentPosition = 0;
	var questionID = 0;
	var parentID = 0;
	var gender = "";
	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 Gender
	if (document.form1.gender.value) {
		var othergender = "";
		gender = document.form1.gender.value;
		(gender == "male") ? othergender = "female" : othergender = "male";
		$(".gendertitle").addClass(gender + "title");
		$(".gendertitle").removeClass(othergender + "title");
		$(".question-" + gender).show();
		$(".question-" + othergender).hide();
	}


	$('.control').click(function(){
		if ($(this).hasClass("evaluatequiz")) evaluateResults("quiz");
		if ($(this).hasClass("evaluateprofile")) evaluateResults("profile");
		if ($(this).hasClass("fullstartover")) {
			currentPosition = currentPosition + parseInt($(this).attr("rel"));
			startover();
			$('#slideInner').css({ 'marginLeft': '0'});
		} else {
			//alert("ul#" + currentQuestionID + " li   " + currentQuestionID + "___" + $("ul#" + currentQuestionID + " li").hasClass("btnchecked"));
			if ($(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;
	});

	$('.selectgender a').click(function(){
		var othergender = "";
		gender = $(this).attr("rel");
		$(".gendertitle").addClass(gender + "title");
		document.form1.gender.value = gender;
		(gender == "male") ? othergender = "female" : othergender = "male";
		$(".gendertitle").removeClass(othergender + "title");
		$(".question-" + gender).show();
		$(".question-" + othergender).hide();

		currentPosition++;
		$('#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");
			$("#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,
				lovelanguage: llName[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 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, I'm sorrys 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;
