$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}
$(document).ready(function(){	
	$('ul#menu li a').hover(function(){
			//var str = $(this).attr("href").substr(0);
			var str = $(this).attr("href").substr(1) ;
			if(!$(this).hasClass("ativo")){
			$('#'+str).stop().animate({"opacity": 1},{queue:false,duration:350});			
			$(this).stop().animate({"opacity": 0},{queue:false,duration:500});
			}
		}, function() {
			if(!$(this).hasClass("ativo")){
			$('#'+$(this).attr("href").substr(1)).stop().animate({"opacity": 0},{queue:false,duration:350});	
			$(this).stop().animate({"opacity": 1},{queue:false,duration:350});
			}
	});
	$("#rs").click(function(){
		$("#login-holder").slideToggle({duration:600,easing:"easeOutBounce"});
	});
	$("#entrar").click(function(){
			$("#fld_ext").stop().animate({"width": "960px"},350,function(){
			$.post("/processor.php",$("#login-holder").serialize(),function(e){
				if(e!=1){
					$("#msg").text(e);
				}
				else {
					$("#msg").text("Aguarde o redirecionamento ...");
					$("#msg").fadeIn("fast",function(){
						$("#login-holder").submit().delay(1000);
					});
				}
				$("#msg").fadeIn();
			});	
		});			
		return false;
	});
	$("#enviar").click(function(){
		$.post("/processor.php",$("#cnt").serialize(),function(f){
			$("#msg-cnt").html(f);
			$("#msg-cnt").fadeIn(); 
		});
		return false;
	});
	$("#cadastrar").click(function(){
		$.post("/processor.php",$("#newsletter").serialize(),function(g){
			window.alert(g);
		});
		return false;
	});
	//Busca Interativa
	$("input#busca_filtro").blur(function(){
	 	$('#sugestoes').fadeOut();
	 });
	$("input#busca_filtro").keyup(function(){
		if($("input#busca_filtro").attr('value').lenght ==  0) {
			$('#sugestoes').fadeOut(); // Hide the suggestions box
		} else { 
			$.post("/processor.php", {op:"busca" ,queryString: ""+$("input#busca_filtro").attr('value')+""}, function(data) { // Do an AJAX call
				$('#sugestoes').fadeIn(); // Show the suggestions box
				$('#sugestoes').html(data); // Fill the suggestions box
			});
		}
	});
});