$(document).ready(function(){
						   
	$.preloadImages("images/nav_serve_over.jpg", "images/nav_about_over.jpg", "images/nav_facilities_over.jpg", "images/nav_help_over.jpg", "images/nav_careers_over.jpg", "images/nav_faqs_over.jpg", "images/nav_contact_over.jpg", "images/bg_field_left_focus.jpg", "images/bg_field_right_focus.jpg", "images/bg_field_mid_focus.jpg", "images/bg_comment_mid_focus.jpg", "images/bg_comment_left_focus.jpg", "images/bg_field_right_focus.jpg" );
	
	$('#footer-content ul li img').last().css('margin','0px');
	
	$(".over").hover(
		function(){
			source = $(this).find("img").attr("src");
			source = source.replace("_off","_over");
			$(this).find("img").attr("src",source);
		},
		function(){
			source = $(this).find("img").attr("src");
			source = source.replace("_over","_off");
			$(this).find("img").attr("src",source);
     });
	
	/*($(".NuContentNavLevel1").click(function(){
     	window.location=$(this).find("a").attr("href");
     	return false;
	});*/
	
	if ($(".navLevel2Selected").length > 0){
		$(".navLevel2Selected").prevAll('.navLevel1').first().addClass('navLevel1Selected').removeClass('navLevel1'); 
	}
	
	$('#sub-right').find('.content:first').css("padding-top","0px");
	
	$('.field').each(function(){
		$(this).focus(function(){
			$(this).css("background-image","url(images/bg_field_mid_focus.jpg)");
			$(this).prev(".field-left").css("background-image","url(images/bg_field_left_focus.jpg)");
			$(this).next(".field-right").css("background-image","url(images/bg_field_right_focus.jpg)");
		}).blur(function(){
			$(this).css("background-image","url(images/bg_field_mid.jpg)");
			$(this).prev(".field-left").css("background-image","url(images/bg_field_left.jpg)");
			$(this).next(".field-right").css("background-image","url(images/bg_field_right.jpg)");
		});
	});
	$('.form textarea').each(function(){
		$(this).focus(function(){
			$(this).css("background-image","url(images/bg_comments_mid_focus.jpg)");
			$(this).prev(".textarea-left").css("background-image","url(images/bg_comments_left_focus.jpg)");
			$(this).next(".textarea-right").css("background-image","url(images/bg_comments_right_focus.jpg)");
		}).blur(function(){
			$(this).css("background-image","url(images/bg_comments_mid.jpg)");
			$(this).prev(".textarea-left").css("background-image","url(images/bg_comments_left.jpg)");
			$(this).next(".textarea-right").css("background-image","url(images/bg_comments_right.jpg)");
		});
	});
	
	$('.fieldselect').each(function(){
		$(this).selectmenu({
			'style'			:'dropdown',
			'maxHeight'	:200					   
		});
	});
	
	if ($("#Contact").length > 0){
		$("#Contact").validate({
			errorPlacement: function(error, element) {
				error.insertAfter(element.next(".field-right"));
			},
			debug:true,
			submitHandler: function(form) {
				$.ajax({
					type: 'POST',
					url: 'submit.jsp',
					data: {
						'Name': $('#Name').val(),
						'Address': $('#Address').val(),
						'City': $('#City').val(),
						'State': $('#State').val(),
						'Zip': $('#Zip').val(),
						'Phone': $('#Phone').val(),
						'Email': $('#Email').val(),
						'Best Way to Contact': $('input[name=Best_Way_to_Contact]:checked').val(),
						'Program of Interest': $('input[name=Program_of_Interest]:checked').val(),
						'Children Options': $('#Children_Options option:selected').val(),
						'Family Options': $('#Families_Options option:selected').val(),
						'Adult Options': $('#Adults_Options option:selected').val(),
						'Senior Options': $('#Seniors_Options option:selected').val(),
						'How Did You Find Out About Us': $('#How_Did_You_Find_Out_About_Us option:selected').val(),
						'Comments': $('#Comments').val()
					},
					success: function(data) {
						$('#dialog-modal').dialog({ buttons: { "OK": function() { $(this).dialog("close"); } } }); 
					},
					error: function(error) {
						$('#dialog-failed').dialog({ buttons: { "OK": function() { $(this).dialog("close"); } } });
					}
				});
			}
		});
	}
	
	$('#CreditCard').click(function(){
		$('#cc_form').slideToggle("slow");
		$('#cash_form').css("display","none");
		/*$('.fieldselect2').each(function(){
			$(this).selectmenu({
				'style'		:'dropdown',
				'maxHeight'	:200					   
			});
		})*/;
	});
	$('#CashCheckMO').click(function(){
		$('#cc_form').css("display","none");
		$('#cash_form').slideToggle("slow");
	});
	
	$('.next1').click(function(){
		jQuery.validator.addMethod("defaultInvalid", function(value, element) {
			if(element.value=="$"){
         		return false;
			}
			return true;
		});
		jQuery.validator.addMethod("selectNone", function(value, element) {
			if (element.value == "")
				return false;
			else 
				return true;
		},
		"Please select an option."
		);
		$('#Donate').validate({
			errorPlacement: function(error, element) {
				if(element.is("input")){
					error.insertAfter(element.next(".field-right"));
				}
				if(element.is("select")){
					error.insertAfter(element);
				}
			},
			rules: {
				DonationAmount: "required defaultInvalid",
				State: {
					selectNone: true
				}
			},
			messages: {
				DonationAmount: "This field is required",
				State: "This field is required"
			}
		});
  		
		if($("#Donate").valid()==true){
			$('#cc_form').css("display","none");
			$('#cc_form2').animate({width: 'toggle'});
			/*$('.fieldselect2').each(function(){
				$(this).selectmenu({
					'style'		:'dropdown',
					'maxHeight'	:200					   
				});
			});*/
		}
	});
	$('.prev1').click(function(){
		$('#cc_form').slideToggle("slow");
	});
	$('.prev2').click(function(){
		$('#cc_form2').css("display","none");
		$('#cc_form').animate({width: 'toggle'});	
	});
});

jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
}

function printPage(){
	window.print();
}
function clearDefault(field){
	if(field.value == field.defaultValue){
		field.value = "";
	}
}
function restoreDefault(field){
	if(field.value == ""){
		field.value = field.defaultValue;
	}
}
