$().ready(function() {
	if(document.getElementById('busca'))
		busca();
});

function busca() {
	$('#palavra').focus(function() {
		$(this).animate({color : '#000000'}, 200);
		$(this).parent().css({backgroundPosition : 'left bottom'});
		$('span', $(this).parent()).animate({color : '#000000'}, 200);
	});

	$('#palavra').keyup(function(e) {
		$(this).animate({color : '#000000'}, 200);
		$(this).parent().css({backgroundPosition : 'left bottom'});
		$('span', $(this).parent()).animate({color : '#000000'}, 200);

		if($(this).val().length > 0) {
			$('span', $(this).parent()).stop(false, true).fadeOut(200);
		} else {
			$('span', $(this).parent()).stop(false, true).fadeIn(200);
		}

		if(document.getElementById('right')) {
			if($(this).val().length > 0) {
				$('#palavra').stopTime('busca');

				$('#palavra').oneTime(200, 'busca', function() {
					carrega_produtos('?' + $('#busca form').serialize(), false);
				});
			}
		}
	});

	$("#palavra").blur(function() {
		if($(this).val() == '') {
			$(this).animate({color : '#666666'}, 200);
			$(this).parent().css({backgroundPosition : 'left top'});
			$('span', $(this).parent()).animate({color : '#666666'}, 200);

			$('span', $(this).parent()).fadeIn(200);
		}
	});

	$('#form_bus').submit(function() {
		var error_bus = false;
		var input_bus = '';

		$(input_bus, '#busca form').focus();

		if((error_bus) && ($('#palavra').val().length >= 2)) {
			input_bus = 'palavra';
			error_bus = true;
		}

		if(document.getElementById('right')) {
			if(!error_bus) {
				carrega_produtos('?' + $(this).serialize(), false);
			}

			return false;
		} else {
			return true;
		}
	});
}
