function slip_utils() {	
	$('a[rel*=facebox]').facebox();
	
	$('.links .contact').click(function() {	
		show_control('.message');			
	});
	
	$('.links .tell').click(function() {
		show_control('.tell');
	});

	$('.links .earth').click(function() {
		show_control('.earth');
		id = $('.message .send').attr("value");
		url = "/slips/" + id + ".kml";
		window.open(url);
	});
	
	$('.toggle_geowake').click(function() {
		if($(this).attr("checked")) {
			gw.AddOverlay();
		} else {
			gw.RemoveOverlay();
		}
	});
	
	$('.message .send').click(function() {		
		id = $(this).attr("value");
		body = $('.msg_body').val();
		
		email = null;		
		if ($("#email")) {
			email = $("#email").val();
		}
		
		$.ajax({		
			url: "/messages",
			dataType: "html",
			type: "POST",
			data: { slip_id:id,
				 	message:body,
					email:email,
				 	authenticity_token: $('#token').val()
				 },					
			beforeSend: function(xhr) {
				xhr.setRequestHeader("Accept", "text/html");				
				show_spin();
			},
			success: function(html) {	
				hide_spin();
				alert("Your message was sent!");				
	        },
		    error: function(msg) {
				hide_spin();
				alert("There was a problem sending the message.  Please verify your email address and try again.");				
			}
		});			
			
		return false;
	});
}

function show_control(ctrl) {	
	$('.controls .message').hide();
	$('.controls .tell').hide();
	$('.controls .earth').hide();
	$('.controls ' + ctrl).show();
}

function show_spin() {
	$('.contact .send').hide();
	$('.spinner').show();
}

function hide_spin() {
	$('.contact .send').show();
	$('.spinner').hide();
}