// Global vars
var hash = "MT";
var goTo = "MT";
var quickJump = false;

$(document).ready(function(){

	/////////////////////////////////////////////////////////////////
	// Deep-linking tabs. Options are #beauty #style and #fashion

	if (window.location.hash != null){
		hash = window.location.hash;
	}
		
	if( hash.length >= 4  ) {

		goTo = hash.substring(1);
		var jumpLeft = 0;

		if ( goTo == "fashion" ){

			jumpLeft = 2;

		} else if ( goTo == "style" ){
	
			jumpLeft = 1;
		}

		$("#bookit_subnav_tab").animate({ left: ((69 * jumpLeft) + 3 )+"px"}, 0);
		$("#bookit_carousel").animate({ left: "-"+(385 * jumpLeft )+"px"}, 0);
	}

	/////////////////////////////////////////////////////////////////
	// Move carousel and nav highlighter
	$('.move_bookit').click(function(){

		var howFarLeft = $(this).attr("rel");
		$("#bookit_subnav_tab").animate({ left: ((69 * howFarLeft) + 3 )+"px"}, 400);
		$("#bookit_carousel").animate({ left: "-"+(385 * howFarLeft )+"px"}, 400);

		var newHash = $(this).attr("alt");
		newHash = newHash.toLowerCase();
		setLocationHash(newHash);
	});

	/////////////////////////////////////////////////////////////////
	// Open all different book it forms
	$('.open_bookit_forms').click(function(){

		var timeURL = "getEventTimes.php?type=" +  $(this).attr("rel");

		$.ajax({ url: timeURL, success: function(table){
			 
			 $("#"+openWhichForm+"_table_ajax").html(table).customFadeIn(400, function(){});
				 
		}});

		var openWhichForm = $(this).attr("alt");
		$("#"+openWhichForm).customFadeIn(500, function(){});
	});

	// Close all different book it forms
	$('.close_bookit_forms').click(function(){

		var closeWhichForm = $(this).attr("alt");
		$("#"+closeWhichForm).fadeOut(500);
	});

	/////////////////////////////////////////////////////////////////
	// Book It: Beauty

	$('#beauty_signup').validate(profileValBeauty);

	/////////////////////////////////////////////////////////////////
	// Book It: Style

	$('#style_signup').validate(profileValStyle);

	/////////////////////////////////////////////////////////////////
	// Book It: Fashion

	$('#fashion_signup').validate(profileValFashion);

}); // End (document).ready

/////////////////////////////////////////////////////////////////

function setLocationHash(value){
	window.location.hash = value;
	return false;
}

/////////////////////////////////////////////////////////////////

function thankYou(time){

	//alert("time: "+time); 
	$(".form_panel").fadeOut(500);
	$("#thank_you").customFadeIn(500, function(){});
	$("#appt_time").html(time);
}

/////////////////////////////////////////////////////////////////

function thankYouOverflow(response){

	//alert("time: "+time); 
	$(".form_panel").fadeOut(500);
	$("#thank_you_overflow").customFadeIn(500, function(){});
	$("#overflow_response").html(response);
}

/////////////////////////////////////////////////////////////////
// Book It: Beauty

	//Make your validation rules into an object:
	profileValBeauty = {};
	
	//The rules to validate against
	profileValBeauty.rules = {
		eventtype: {
			required: true
		},
		firstname : {
			required: true
		},
		lastname : {
			required: true
		},
		email : {
			required: true,
			email: true
		},
		phone : {
			required: true
		}
	};	
	
	//Optional - if you want a custom message
	profileValBeauty.messages = {
		firstname: {
			required: "Please enter your first name"
		},
		lastname: {
			required: "Please enter your last name"
		},
		email: {
			required: "Please enter your email address",
			email: "Please enter a valid email address"
		},
		phone: {
			required: "Please enter your phone number"
		}
	};	
	
	//Optional - if you want the error message to appear in a separate div
	profileValBeauty.errorLabelContainer = '#errorbox_prof_beauty';
	profileValBeauty.wrapper= 'div';

	profileValBeauty.submitHandler = 
		function(form) {
			jQuery(form).ajaxSubmit({
			success: function(data) {

				thankYouOverflow(data);
				$("#beauty_signup").clearForm();
			}
		});
	};

/////////////////////////////////////////////////////////////////

// Book It: Style

	//Make your validation rules into an object:
	profileValStyle = {};
	
	//The rules to validate against
	profileValStyle.rules = {
		eventtype: {
			required: true
		},
		firstname : {
			required: true
		},
		lastname : {
			required: true
		},
		email : {
			required: true,
			email: true
		},
		phone : {
			required: true
		}
	};	
	
	//Optional - if you want a custom message
	profileValStyle.messages = {
		firstname: {
			required: "Please enter your first name"
		},
		lastname: {
			required: "Please enter your last name"
		},
		email: {
			required: "Please enter your email address",
			email: "Please enter a valid email address"
		},
		phone: {
			required: "Please enter your phone number"
		}
	};	
	
	//Optional - if you want the error message to appear in a separate div
	profileValStyle.errorLabelContainer = '#errorbox_prof_style';
	profileValStyle.wrapper= 'div';

	profileValStyle.submitHandler = 
		function(form) {
			jQuery(form).ajaxSubmit({
			success: function(data) {

				thankYouOverflow(data);
				$("#style_signup").clearForm();
			}
		});
	};

/////////////////////////////////////////////////////////////////

// Book It: Fashion


	//Make your validation rules into an object:
	profileValFashion = {};
	
	//The rules to validate against
	profileValFashion.rules = {
		eventtype: {
			required: true
		},
		firstname : {
			required: true
		},
		lastname : {
			required: true
		},
		email : {
			required: true,
			email: true
		},
		phone : {
			required: true
		}
	};	
	
	//Optional - if you want a custom message
	profileValFashion.messages = {
		firstname: {
			required: "Please enter your first name"
		},
		lastname: {
			required: "Please enter your last name"
		},
		email: {
			required: "Please enter your email address",
			email: "Please enter a valid email address"
		},
		phone: {
			required: "Please enter your phone number"
		}
	};	
	
	//Optional - if you want the error message to appear in a separate div
	profileValFashion.errorLabelContainer = '#errorbox_prof_fashion';
	profileValFashion.wrapper= 'div';

	profileValFashion.submitHandler = 
		function(form) {
			jQuery(form).ajaxSubmit({
			success: function(data) {

				thankYouOverflow(data);
				$("#fashion_signup").clearForm();
			}
		});
	};
