var m;
var temp;

function slideSection(){
	$(".section .inner h4 span").mouseover(function(){
		if ($(this).parents(".inner").find(".toggle").hasClass("on")){
			$(this).css("cursor","default");
		} else {
			$(this).css("cursor","pointer").addClass("over");
		}
	}).mouseout(function(){
		$(this).removeClass("over");
	})
	$(".section .inner h4 span").click(function(){
		if ($(this).parents(".inner").find(".toggle").hasClass("on")){
			return false
		} else {
			clearTimeout(m);
			temp = $(this);
			m = setTimeout(function(){sliding(temp)},200);
		}
	})
}

function sliding(xx){
	$(".toggle.on").prev("h4").find("span").removeClass("on");
	$(".toggle.on").slideToggle("slow").removeClass("on");			
	xx.parents(".inner").find(".toggle").slideToggle("slow").addClass("on").end().find("span").addClass("on");
}


function pencilInteract(name){
	$(name).hover(function(){
		$(this).css({
			"height":"300px",
			"cursor":"pointer"
		});
		$(this).find(".unitExpand").slideDown();
	}, function(){
		$(this).css({
			"height":"auto",
			"cursor":"pointer"
		});
		$(this).find(".unitExpand").hide();
	});
	$(name).find(".unitExpand").mouseover(function(){
		$(this).css("cursor","pointer");
	});	
}

function contactValidate(){
	$("#contactForm").validate({
		success: function(label){
			if(label.attr("for") == "math"){
				label.addClass("valid").text("Correct Answer!").wrapInner("<span></span>");
			} else {
				label.addClass("valid").text("Ok!").wrapInner("<span></span>");
			}
		},
		rules: {
			fullName: {
				required: true
			},
			emailAddress: {
				required: true,
				email: true
			},
			message: {
				required: true
			},
			math: {
				required: true,
				equal: phpRandNum	
			}
		},
		messages: {
			fullName: {
				required: "<span>Your name is required.</span>"
			},
			emailAddress: {
				required: "<span>Your email is required.</span>",
				email: "<span>Please enter a valid email.</span>"
			},
			message: {
				required: "<span>Your message is required.</span>"
			},
			math: {
				required: "<span>Please answer the math question.</span>",
				equal: "<span>Your answer is incorrect.</span>"
			}
		}
	});
}

