$(document).ready(function(){

	$(".abre_fotos").click(function(){
	  if($("#fotos_"+$(this).attr("id")).css("display") == "none"){
	  	$("#fotos_"+$(this).attr("id")).slideDown("normal",function(){
			if($("#texto").height() > 400){
				$(".contBox2").height($("#texto").height())
			}
		})
	  }else{
	  	$("#fotos_"+$(this).attr("id")).fadeOut("normal",function(){
			$(".contBox2").height(400)
		})
	  }
	})

	$(".abre_videos").click(function(){
	  if($("#videos_"+$(this).attr("id")).css("display") == "none"){
	  	$("#videos_"+$(this).attr("id")).slideDown("normal",function(){
			if($("#texto").height() > 400){
				$(".contBox2").height($("#texto").height())
			}
		})
	  }else{
	  	$("#videos_"+$(this).attr("id")).fadeOut("normal",function(){
			$(".contBox2").height(400)
		})
	  }
	})

	$(".tipo_c").click(function(){
	  if($(this).val() == "Curriculo"){
	  	   $("#contato_normal").addClass("hide")  
	  	   $("#contato_curriculo").removeClass("hide")  
	  }else{
	  	   $("#contato_normal").removeClass("hide")  
	  	   $("#contato_curriculo").addClass("hide")  
	  }
	  $("#c_tipo").val($(this).val())
	})


	$("#c_msg").blur(function(){
	    $("#c_msg").val(rtrim($("#c_msg").val())) 
	    $("#c_msg").val(ltrim($("#c_msg").val())) 
	})

	$("#c_msg").keypress(function(){
	  if(event.keyCode == 13){
	  	return false;  
	  }
	})
	
	$("#c_msg").keyup(function(){
		$("#chars").html($("#c_msg").val().length)
	})
	
	$("#enviar_c").click(function(){
	  	if(($("#c_tipo").val() != "") && ($("#c_empresa").val() != "") && ($("#c_email").val() != "") && ($("#c_tel").val() != "") && ($("#c_msg").val() != "")){
		  if($("#c_msg").val().length >= 10 && $("#c_msg").val().length <= 500){
			    document.getElementById('enviar_c').disabled=true
			  	$('#enviar_c').val('Aguarde...')
				$.ajax({ 
					type: "GET",
					url: "funcoes.php",
					async: false, 
					data: "op=2&tipo="+$("#c_tipo").val()+"&empresa="+$("#c_empresa").val()+"&email="+$("#c_email").val()+"&tel="+$("#c_tel").val()+"&msg="+$("#c_msg").val(),
					success: function(){	
		  		 	  $('#enviar_c').val('Enviar')
		  			  document.getElementById('enviar_c').disabled=false
					  alert("Mensagem enviada com sucesso!")
					  window.open("http://www.amer.com.br/?pag=contatos","_top")
					}
				});
			}else{
			   alert("ERRO: A mensagem deve ter no mínimo 10 e no máximo 500 caracteres!")
			}
		}else{
		  alert("ERRO: Verifique se todos os campos foram preenchidos e/ou o tipo de contato foi selecionado!")
		  
		}
	})
	
	$("#enviar_at").click(function(){
      if(($("#at_empresa").val() != "") && ($("#at_email").val() != "") && ($("#at_nome").val() != "") && ($("#at_os").val() != "") && ($("#at_motivo").val() != "") && ($("#at_acomp").val() != "") && ($("#at_compr").val() != "") && ($("#at_msg").val() != "")){
          document.getElementById('enviar_at').disabled=true
          $('#enviar_at').val('Aguarde...')
        $.ajax({ 
            type: "GET",
            url: "funcoes.php",
            async: false, 
            data: "op=1&empresa="+$("#at_empresa").val()+"&email="+$("#at_email").val()+"&nome="+$("#at_nome").val()+"&os="+$("#at_os").val()+"&motivo="+$("#at_motivo").val()+"&acomp="+$("#at_acomp").val()+"&comprador="+$("#at_compr").val()+"&msg="+$("#at_msg").val(),
            success: function(){    
                 $('#enviar_at').val('Enviar')
                document.getElementById('enviar_at').disabled=false
              alert("Mensagem enviada com sucesso!")
              window.open("http://www.amer.com.br","_top")
            }
        });
    }else{
      alert("ERRO: Todos os campos devem ser preenchidos!")
    }
	})
	
	
	$(".vid").click(function(){
  	    hist = window.open('video.php?nome='+$(this).attr("name")+'&titulo='+$(this).attr("title"),'popup','width=600px,height=420px,resizable=yes,scrollbars=yes,left=0,top=0')
		hist.focus()
	})
	
	
	
	$(".cat").click(function(){
		id = $(this).attr("id");
		title= $(this).attr("title");
		nome = id.replace("-","");
		cata = window.open('',nome,'scrollbars=yes,left=0,top=0')
		dados = "<title>"+title+"</title><center><img src='img/pdf.jpg' align='absmiddle'> <a href='catalogos/"+$(this).attr("id")+".pdf' target='_blank' style='color:#000000'>clique aqui para baixar este catálogo</a><br><br><img src='catalogos/"+$(this).attr("id")+"-.JPG' style='border:1px solid #c1c1c1'></center>";
		cata.document.write(dados)
		cata.focus()
	})
	
	
	$(".paint").mouseover(function(){
		$(".paint").css("background-color","#E8E8E8")
		$(this).css("background-color","#FFF")
		$(this).css("text-decoration","underline")
	}).mouseout(function(){
		$(".paint").css("background-color","#E8E8E8")
		$(this).css("text-decoration","none")		
	})

})

	

//########################################################################################################################
