function zoomPico(pico, foto){
	return window.open("zoom-pico.php?pico="+pico+"&foto="+foto,"Zoom","scrollbars=no");
}

//inicialização da Biblioteca
$(document).ready( function(){
	$.carregando = function(visivel){		
		if(!visivel){
			$("#loader").remove();
			return;
		}
		else return "<img id=\"loader\" class=\"verticalMiddle\" src=\"imagens/spinner1.gif\" />";
	}
	
	//ação de exibição do submenu
	var on = false;
	$(".level1 a").hover( 
		function(){
			on = true;
			$(".level1 a").not(this).removeClass("ativo");
			$(this).addClass("ativo");
			$(".submenu").hide();
			$("#"+$(this).attr("targetLevel2")).show();
			$("#"+$(this).attr("targetLevel2")).css("left",$(this).offset().left+"px");
		},function(){
			on = false;
		}
	)
		
	hideIdleMenu = window.setInterval(function(){ 
		if(!on){
			$(".level1 a").removeClass("ativo");
			$(".submenu").hide();
		}
	},1500);
	
	$(".submenu a").hover(
		function(){ on=true },
		function(){ on=false }
	);	
	
	/***** SCRIPTS PARA O LAYOUT *****/		
	//correções para navegadores NON-MSIE6
	IE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	if($.browser.opera||$.browser.mozilla||IE7){
		window.setTimeout(function(){
			$("button").css("padding","1px 0 0 0");
			//$(".item").css({marginBottom:"2px",marginLeft:"0px"});
			$("#footer,#footer-home").css("float","left");
			$(".representantes li").css({paddingTop:"5px",height:"47px"});
			$(".detalhes_acessorios .preco").css("marginBottom","4px");
		},20);
	}
	
	//aplicação do arredondamento de bordas
	$("#home-highlights2 li").corner("5px");
	//correção da cor ao lado da borda arredondada
	$("#home-highlights2 div div").css("borderColor","#41404A");
	//$(".bgDepoimento").css("background","#636369");
	/***** FIM: SCRIPTS PARA O LAYOUT *****/

	//ajax Carrega lista de representantes por cidade
	$("#representantes_pais").change( function(){
		$(this).after( $.carregando(true) );
		$("#representantes_estados").attr("disabled","disabled");
		$("#representantes_cidades").attr("disabled","disabled");
		if(this.value!=0){
			$.get("php/ajax.php",{
				acao:"drop_getEstados",
				pais:$(this).val()
			},function(estados){
				$.carregando(false);
				$("#representantes_estados").attr("disabled","").html("").append(estados);
			});
		}else{
			$.carregando(false);
			$("#retornoAjax").html("<h3>Escolha um país.</h3><br/>");
		}
	});

	//ajax Carrega combobox de cidades por estado
	$("#representantes_estados").change( function(){
		//exibe um carregando
		$(this).after( $.carregando(true) );
		if(this.value!=0){
			$.get("php/ajax.php",{
				acao:"drop_getCidades",
				estado:$(this).val()
			},function(cidades){
				$.carregando(false);
				$("#retornoAjax").html("<h3>Escolha uma cidade.</h3><br/>");
				$("#representantes_cidades").attr("disabled","").html("").append(cidades);
				//$("#representantes_cidades").;
			});
		}else{
			$.carregando(false);
			$("#retornoAjax").html("<h3>Escolha um estado.</h3><br/>");
		}
	});
	
	
	//ajax Carrega lista de representantes por cidade
	$("#representantes_cidades").change( function(){
		$(this).after( $.carregando(true) );
		if(this.value!=0){
			$.get("php/ajax.php",{
				acao:"drop_getRepresentantes",
				cidade:$(this).val()
			},function(lista_representantes){
				$.carregando(false);
				$("#retornoAjax").html(lista_representantes);
			});
		}else{
			$.carregando(false);
			$("#retornoAjax").html("<h3>Escolha um estado.</h3><br/>");
		}
	});
	
	
	//ajax Newsletter
	$("#form-newsletter").submit(function(){
		var _nome = $("#FIELD_Name",this).val();
		var _email = $("#FIELD_Email",this).val();
		var _receber = $("#news-receber",this).val();
		if (_nome.length > 2 || _email.length > 7){
			$(this).slideUp("normal",function(){		
				var container = $("#newsletter");
				$(container)
					.html("")
					.css({ paddingTop:"0", textAlign:"center" });
				$(container)
					.append( $.carregando(true) )
					.append("&nbsp;&nbsp;<strong class=\"verticalAlign\">Cadastrando...</strong>");
				$.post("php/ajax.php",{
					acao : "cadastrarNewsletter",
					FIELD_Name : _nome,
					FIELD_Email : _email
				},function(callback){
					$.carregando(false);
					$(container).html(callback);
				});	//end $.POST			
			});
		}else{
			alert("Complete o formulário com seu nome e email.");
		}	
		return false;
	});
	
	//efeito indicativo para input's do form de newsletter
	$("#newsletter input")
		.focus(function(){ 
			$(this).css({background:"#515151",borderColor:"#888"}) 
		})
		.blur(function(){ 
			$(this).css({background:"#484848",borderColor:"#AF9E61"}) 
	});
	
	//efeito indicativo para input's e textareas em páginas de estilo .contato
	$(".contato").find("input[@type=text], textarea")
		.focus(function(){ 
			$(this).css({borderColor:"#C9AD47"}) 
		})
		.blur(function(){ 
			$(this).css({borderColor:"#888"}) 
	});
	
	//validação do formulário de depoimento
	$("#formDepoimento").submit( function(){
		if( $("#FIELD_Name",this).val().length < 2 || $("#FIELD_Name",this).val().length < 2){
			$("#erroDepoimento").html("Os campos são obrigatórios.");
			return false;
		}
	});
	
	//validação do formulário de 'Fale Conosco'
	$("#formContato").submit( function(){
		if( $("#nome",this).val().length < 2 || $("#email",this).val().length < 2){
			$("#erro",this).html("Os campos são obrigatórios.");
			return false;
		}
	});
	
	//ação de exibição do formulário de depoimento
	$("#deixarDepoimento").toggle( 
		function(){ $(".bg_depoimento").slideDown("normal"); },
		function(){ $(".bg_depoimento").slideUp("normal"); }
	);
	
	/*toggleForm = function(){
		if( $("#formulario").is(":hidden") ){
			$("#formulario").slideDown("normal");
		}
	}*/
		
	//trocar a thumbnail do picocalibragem
	changeLinkPico = function(linker,photo,thumbnail){
		$(linker).addClass("inativo").siblings().removeClass("inativo");
		var anchorPhoto = $("#"+photo); //link da foto
		var link = $(linker).attr("href");
		var titulo = $(linker).attr("rel");
		$(anchorPhoto).unbind("click");
		$(anchorPhoto).bind("click",function(){ //renova o método do onclick do link da img
			return zoomPico(titulo,link);
		});
		$("img",anchorPhoto).attr("src",thumbnail);
	}
	
	//trocar a thumbnail do produto
	$(".trocaSrcProduto").click( function(){
		$(this).addClass("atual").siblings().removeClass("atual");
		var href = $(this).attr("href") || null;
		$("#foto-produto").attr("src",href);
		return false ; //IE6 não está cancelando o disparo (onclick inline foi necessário)
	});
	
	//mostrar screen da tabela de calibragem de pneus
	toggleCalibragem = function (show){
		if (show == 1){
			$("#calibragem").show();
		}else{
			$("#calibragem").hide();
		}
	}
		
	//ajax Picos por estado
	$("#estadoPico").change( function(){
		if(this.value != "null"){
			window.location = this.value;
		}
	});
		
	$("#ride-center-switch").toggle(
		function(){
			$("#ride-center-opt").slideDown("fast");
			$("img",this).attr("src","imagens/up_arrow.gif");
		},
		function(){
			$("#ride-center-opt").slideUp("fast");
			$("img",this).attr("src","imagens/down_arrow.gif");
		}
	);
	
});

function onlynumbers(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        //status = "This field accepts numbers only.";
        return false;
    }
    status = "";
    return true;
}
