// when the DOM is ready...

$(document).ready(function(){
	$("#cf2_field_4,#cf2_field_9").click(function(){
		toggleAddressBoxes();
	});
	
	toggleAddressBoxes();
	
	$("#donation").validate({
	  rules: {
	    email_address: {
	      required: true,
	      email: true
	    },
		donation_total:{
			required:true,
			number:true
		}
		
	  }
	});
	$("#donation").submit(function(){
		return checkRequired();
	});
	$("#radio-1, #radio-2").change(function(){
		showHideEmployer();
	});
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	/*$("#mason-plan, #submenu").mouseover(function(){
		$("#submenu").css("display","block");
	});
	$("#submenu").mouseout(function(){
		$("#submenu").css("display","none");
	});*/
	
	$.preloadImages("/images/menu-taxes-on.png", "/images/menu-government-on.png","/images/menu-seniors-on.png","/images/menu-safety-on.png","/images/menu-green-on.png","/images/menu-development-on.png");

});

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

function toggleAddressBoxes(obj){
	if($("#cf2_field_4").attr('checked') || $("#cf2_field_9").attr('checked')){
		$("#li-2-10").show();
		$("#li-2-11").show();
		$("#li-2-12").show();
		$("#li-2-13").show();
	}else{
		$("#li-2-10").hide();
		$("#li-2-11").hide();
		$("#li-2-12").hide();
		$("#li-2-13").hide();
	}
}



function showHideEmployer(){
	//alert($("input[@name='employed']:checked").val());
	if($("input[@name='employed']:checked").val() == "yes"){
		$(".hide").each(function(){
			$(this).show();
		});
	}else{
		$(".hide").each(function(){
			$(this).hide();
		});
	}
}

function checkRequired(){
	var req=new Array("occupation","employer_name","employer_address","employer_city","employer_state","employer_zip");
	var ok = true;
	for (i = req.length; i > -1; i--) {
		if ($("input[@name='" + req[i] + "']").val() == "") {
			$("input[name='"+req[i]+"']").focus();
			$("input[name='"+req[i]+"']").parent().append('<label for="'+req[i]+'" generated="true" class="error">This field is required.</label>');
			ok = false;
		}
	}
	return ok;
}






