$(function() {

	// Wine sort drop down
	$("#wines-sort").change(function() {
		$("#search_params_order_by").val($(this).val());
		$("#search_params").submit();
	});
	
	// Winekey hovers
	$("#winekey dl.c-b-f dd").append("<div/>");
	
	$("a.send-to-friend").click(function(e) {
		$("#send-to-friend").modal({
			onOpen: modal.open,
			onClose: modal.close
		});
		e.preventDefault();
	});
	$("a.modal").click(function(e) {
		e.preventDefault();
	});
	
	$("#send-to-friend form").ajaxForm({
		loading: function() {
			this.addClass("processing");
		},
		success: function(response) {
			this.removeClass("processing")
				.parent().removeClass("bad-from-email bad-to-email bad-name");

			if (response.success) {
				$.modal.close();
			} else {
				this.parent().addClass(response.message);
			}
		},
		error: function(response) {}
	});
});
