$(function() {
	//Old browser support for :last-child
	$("#nav ul li:last-child").addClass("last");	
	
	//Hide labels for forms on focus
	$(".form input[type=text], .form textarea").focusin(function() {
		$(this).parent().children("label").hide();
	});
	$(".form input[type=text], .form textarea").focusout(function() {
		if($(this).val()=="")
			$(this).parent().children("label").fadeIn(200);
	});
	
	//Initiate the slideshow
	if($("ul#banner").length){
		$("ul#banner").cycle({
			fx:     "scrollHorz", 
			speed:    1000, 
			timeout:  6000
		});
	}
	
	//Form validation
	if($("#appointment").length) {
		$("#appointment").validationEngine();
	}
	if($("#reviewSignUp").length) {
		$("#reviewSignUp").validationEngine();
	}
	if($("#contact").length) {
		$("#contact").validationEngine();
	}
	
	//Control the cta buttons
	if($("#cta").length) {
		$(".cta_appointment").click(function() {
			if($("#appointment").length) {
				$("#appName").focus();
				formHint($("form#appointment"),300);
			} else {
				document.location.href = "/?page_id=45";
			}
		});
		$(".cta_wellness").click(function() {
			$("#revName").focus();
			formHint($("form#review"),300);
		});
	}
});

function formHint(element,speed) {
	element.prepend('<div class="arrow">&raquo;</div>');
	for(i=0;i<5;i++) {
		element.find(".arrow").animate({"left":"-=10"},speed).animate({"left":"+=10"},speed);
		if(i==4) {
			element.find(".arrow").fadeOut(speed*3);
		}
	}
};
