// JavaScript Document

/*var $ = jQuery.noConflict(); */

$(document).ready(function(){

	// set default form input field values
	$("#search_mini_form #search").val('search');
	
	// on text field focus remove custom text
		$("#search_mini_form #search").focus(function(){
			var email = $("#search_mini_form #search").val();
			if (email == 'search') { $("#search_mini_form #search").val(''); }
		});
		$("#search_mini_form #search").focusout(function(){
			var email = $("#search_mini_form #search").val();
			if (email == '') { $("#search_mini_form #search").val('search'); }
		});


	// set default form input field values
	// used to be ZIP
	$("#address").val('enter your zip code here');
		

	// on text field focus remove custom text
		$("#address").focus(function(){
			var $zip = $("#address").val();
			if ($zip == 'enter your zip code here') { $("#address").val(''); }
		});
		$("#address").focusout(function(){
			var $zip = $("#address").val();
			if ($zip == '') { $("#address").val('enter your zip code here'); }
		});
	
	// store-locator lightbox effect call
	$("a#show-store").click(function(){
		$("#lightbox-store-bg, #lightbox-store").fadeIn(300);
		return false;
	})
	$("a#close-store").click(function(){
		$("#lightbox-store-bg, #lightbox-store").fadeOut(300);
		return false;
	})
	
	// on text field focus remove custom text
		$("#name").focus(function(){ if ($(this).val() == 'Name') { $(this).val(''); } });
		$("#phone").focus(function(){ if ($(this).val() == 'Phone') { $(this).val(''); } });
		$("#email").focus(function(){ if ($(this).val() == 'Email') { $(this).val(''); } });
		$("#state").focus(function(){ if ($(this).val() == 'State') { $(this).val(''); } });

		$("#contact #submit").click(function(){
			$(this).hide();
			var emailVal = $("#email").val();	
			var nameVal = $("#name").val();
			var phoneVal = $("#phone").val();
			var stateVal = $("#state").val();
			var depVal = $("#department").val();
			var commentVal = $("#comment").val();
			$("#contactform ul").hide(1000);
			$("#toHide").append('<p style="padding: 0 0 40px 0">Loading...</p>');

			$.post("http://www.decolav.com/js/sendEmail.php",{ email: emailVal, name: nameVal, phone: phoneVal, state:stateVal, department: depVal, comment: commentVal }, function(data){
				$("#toHide").find("p").html("Thank You for your message! We'll get back to you shortly.<br /><br />");
			});

			return false;
		});

});
