$(document).ready(function() {

	//preset United States as Residency and Citizenship 
	$("#control_current_country").hide();
	$("#control_citizen_country").hide();
	$('#residentyes').attr("checked",true);	
	$('#citizenyes').attr("checked",true);
	
	//control show/hide of country of residence field 
	$('.resident').click(function(){
		if($(this).val()==="yes"){
			
			$("#control_current_country").slideUp("fast");
			$("#country").val("united states");	
			$("#state").val("");	
		};
		if($(this).val()==="no"){
			
			$("#control_current_country").slideDown("fast");
			$("#country").val("");	
			$("#state").val("nonres");	
		};
	});
	
	//control show/hide of country of citizenship 
	$('.citizen').click(function(){
		if($(this).val()==="yes"){
			$("#control_citizen_country").slideUp("fast");
			$("#cit_country").val("united states");
							
		};
		if($(this).val()==="no"){
			$("#control_citizen_country").slideDown("fast");			
			$("#cit_country").val("");
				
		}
	});
	
	//if user changes citizenship field to United States, hide the field and reset radio button 
	$("#cit_country").click(function(){
		if($(this).val()==="united states"){
			$('#citizenyes').attr("checked",true);
			$('#citizenno').attr("checked",false);
			$("#control_citizen_country").slideUp("fast");
		}
		else{
			$('#citizenyes').attr("checked",false);
			$('#citizenno').attr("checked",true);
		};
	});
	//if user changes residence field to United States, hide the field and reset radio button 
	$("#country").click(function(){
		if($(this).val()==="united states"){
			$('#residentyes').attr("checked",true);
			$('#residentno').attr("checked",false);
			$("#control_current_country").slideUp("fast");
			$("#state").val("");	
		}
		else{
			$('#residentyes').attr("checked",false);
			$('#residentno').attr("checked",true);
		};
	});
	
	//if user changes state field to "nonresident", set residence radio button to no and show country of residence dropdown
	$("#state").click(function(){
		if($(this).val()==="nonres"){
			$('#residentyes').attr("checked",false);
			$('#residentno').attr("checked",true);
			$("#control_current_country").slideDown("fast");
			$("#country").val("");	
		};
		
	});
	
	
});
