$(document).ready(function() {
	// this js is required for setting the correct price for the wine product based on bulk/bottle select --}
	$('form.foxycart #per_case').bind('change', function() {
		$('span.price_label').hide();
		if( $(this).val().match(/case/) ) {
			$('input[name="price"]').val($('span.case').text().replace(/\$/, ''));
			$('span.case').show();
		} else {
			$('input[name="price"]').val($('span.bottle').text().replace(/\$/, ''));
			$('span.bottle').show();
		}
	}).trigger('change');
	$('form.foxycart input.amount').bind('focus', function() {
		var $el = $(this);
		var val = $('input#'+$el.attr('id')+'_submit').val();
		$('input[name="per_case"]').val(val);
		if($el.attr('id') == 'case')
			$('input#bottle').val('');
		else
			$('input#case').val('');
		$('input[name="quantity"]').val('');
		return true;
	}).bind('keyup', function() {
		$('input[name="quantity"]').val($(this).val());
		return true;
	});
	$('form.foxycart input[name="submit"]').bind('click', function() {
		$('input[name="per_case"]').val($(this).val());
		if($('input[name="per_case"]').val().match(/case/)) {
			$('input[name="price"]').val($('input[name="x\:price_bulk"]').val().replace(/\$/, ''));
		} else {
			$('input[name="price"]').val($('input[name="x\:price_original"]').val().replace(/\$/, ''));
		}
		
		return true;
	});
	// this js is used for the advanced search results and pagination of those results. --}
	$('.paginate_links a').bind('click', function() {
		var $hidden_form = $('form#advanced_search');
		if( $hidden_form.length > 0 ) {
			$hidden_form.attr('action', $(this).attr('href'));
			$hidden_form.submit();
			return false;
		}
		return true;
	});
});
