showMoreReviews = function() {
	$('#more-reviews-tmp').load(moreReviewsUrl, {from: offset});
}

findReviews = function() {

	rewh = null;
	var q = $('#product_reviews_q').val();
	
	$.get(moreReviewsUrl, {from: 0, q: q},
			function (q, result) {
				$('#reviews').html(result);
				
				if (q.length == 0) {
					$('#show-more-reviews').show();
				} else {
					$('#show-more-reviews').hide();					
				}
			}.curry(this, [q]),
			'html'
	);
}
var rewh = null;

$(function () {
	$('#product_reviews_q').keypress(function(e) {
		
		var q = $('#product_reviews_q').val();
		
		if (q.length > 3 || q.length == 0) {
			if (rewh) {
				clearTimeout(rewh);
				rewh = null;
			}
			
			rewh = setTimeout('findReviews()', 500);
		}
		
		
		
	});
});
