
$(document).ready(function(){

	$(".tipo").click(function(){
	  $(".tipo").css("font-weight","normal");
	  $(this).css("font-weight","bold");
	  $("#tipoEsc").val($(this).text());
	  monta_lista($("#tipoEsc").val(),$("#letraEsc").val())
	})

	$(".letra").click(function(){
	  $(".letra").css("font-weight","normal");
	  $(this).css("font-weight","bold");
	  $("#letraEsc").val($(this).text());
	  monta_lista($("#tipoEsc").val(),$("#letraEsc").val())
	})
	
	$(".link").mouseover(function(){
	  $(this).animate( { fontSize:"12pt" }, 100, function(){
		  PlaySound('musics/click4.wav')
		})
	  if($(this).css("color") == "#ffffff"){
	  	  $(this).css("color","#FFFFC6")
	  }
	}).mouseout(function(){
	  $(this).animate( { fontSize:"10pt" },200)
	  if($(this).css("color") == "#ffffc6"){
		  $(this).css("color","#FFFFFF")
	  }
	})

	$(".link").click(function(){
	  	pag = this.id
	  	window.open('?pag='+pag,'_top')
	})
	
	$("#box2").slideDown("slow",function(){
		$("#rodape").fadeIn("slow");    
	});    
	
	if($("#texto").height() > 400){
		$(".contBox2").height($("#texto").height())
	}

	$(".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)
		})
	  }
	})
	
	$(".abre_mapa").click(function(){
	  $("#div_mapa").slideDown("normal",function(){
		if($("#texto").height() > 400){
			$(".contBox2").height($("#texto").height())
		}
		})
	})
	$("#foto_mapa").click(function(){
	  $("#div_mapa").fadeOut("normal",function(){
		$(".contBox2").height(400)
	  })
	})


	$(".cat").mouseover(function(){
	  $("#legenda").html("<span class='legenda'><i>"+this.name+"</i></span>")
	}).mouseout(function(){
	  if($(this).width() <= 100){
	  	$("#legenda").html("<span class='legenda'>(clique no catálogo para ampliar / fazer download)</span>")
	  }else{
	  	$("#legenda").html("<span class='legenda'>(Para baixar o utilize o link destacado em amarelo / Clique no catálogo para reduzir)</span>")
	  }
	}).click(function(){
	  if($(this).width() == "100"){
			$(this).attr("src","catalogos/"+$(this).attr("id")+"-.JPG") 
			$("#download_cat").html("&nbsp&nbsp&nbsp <img align='absmiddle' src='img/pdf.jpg' alt=''> <a href='catalogos/"+$(this).attr("id")+".pdf' target='_blank'><span>Clique aqui para baixar</span></a>")
			if(detectBrowser() == "Microsoft Internet Explorer"){
		 	  	$(this).css("position","absolute")
		 	  	
			}else{
		 	  	$(this).css("position","relative")
			}
	 	  	$(this).animate( { width:"518px" }, 800, function(){
				if(detectBrowser() == "Microsoft Internet Explorer"){
					$(this).css("left","10px")
				}
			})
	 	  	
 	  }else if ($(this).width() == "518"){
	 	  	$(this).animate( { width:"100px" }, 1000,function(){
				$("#download_cat").html("")
		 	  	$(this).css("position","static")
			})
			
  	  }else if(($(this).width() == "150")){
			$(this).attr("src","catalogos/"+$(this).attr("id")+"-.JPG") 
			$("#download_cat").html("&nbsp&nbsp&nbsp <img align='absmiddle' src='img/pdf.jpg' alt=''> <a href='catalogos/"+$(this).attr("id")+".pdf' target='_blank'><span>Clique aqui para baixar</span></a>")
			if(detectBrowser() == "Microsoft Internet Explorer"){
		 	  	$(this).css("position","absolute")
			}else{
		 	  	$(this).css("position","relative")
			}
	 	  	$(this).animate( { width:"700px" }, 1000, function(){
				if(detectBrowser() == "Microsoft Internet Explorer"){
					$(this).css("left","1px")
				}				     
			})
	 	  	
	  }else{ //540
	 	  	$(this).animate( { width:"150px" }, 1000,function(){
				$("#download_cat").html("")
		 	  	$(this).css("position","fixed")
			})
	  }
	})


	$(".fot").mouseover(function(){
	}).mouseout(function(){
	}).click(function(){
  	    hist = window.open('','popup','width=600px,resizable=yes,scrollbars=yes,left=0,top=0')
		hist.document.write("<script type='text/javascript' src='funcoes_fotos.js'></script><link rel='stylesheet' type='text/css' media='all' href='estilo.css' /><title>AMER Tecnologia em Automação</title><center><b>"+$(this).attr("title")+"</b><br><br><img src='solucoes/fotos/"+$(this).attr("name")+"'></center><br><br><br>") 
		hist.focus()
	})

	$(".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()
	})
	
	$("#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!")
		}
	})

	$(".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","_top")
					}
				});
			}else{
			   alert("ERRO: A mensagem deve ter no mínimo 10 e no máximo 500 caracteres!")
			}
		}else{
		  alert("ERRO: Todos os campos devem ser preenchidos")
		  
		}
	})


	$("#open_foto").click(function(){
	   $("#open_foto").empty()
	})
	
	

	$("#exibirCats_txt").click(function(){
	  $(".cat").each(function(){
	    $(this).fadeOut(1000,function(){
		    $("#lista_cats_texto").append("<br><p align='left'><img src='img/pdf.jpg' align='absmiddle'> <a href='catalogos/"+$(this).attr("id")+".pdf' target='_blank'>" + $(this).attr("name")+"</a></p>")
		})
	  })
	})
	
	$("#exibirCats_img").click(function(){
	  $("#lista_cats_texto").empty()
	  $(".cat").each(function(){
	    $(this).fadeIn(2000)
	  })
	})


	move_estrutura()
	move_clientes()
	verifica_resolucao()
	pisca_download()	
	
	
/*	$("#EstrutFotos table").mouseover(function(){
		  $("#EstrutFotos table").addClass("parado")
	  }).mouseout(function(){
		  $("#EstrutFotos table").removeClass("parado")
		  x = $("#EstrutFotos table").css("left")
		  x = x.replace("px","")
		  y = $("#EstrutFotos table").width() + 8
		  y = y - x 
		  move_estrutura(y)
	}) */
	
})


function ltrim(str){
    return str.replace(/^\s+/,"");
}

function rtrim(str){
    return str.replace(/\s+$/,"");

}


function pisca_download(){
  	$("#download_cat").fadeOut(500,function(){
	  	$("#download_cat").fadeIn(800,function(){
		  	pisca_download()
		})
	})
}

function verifica_resolucao(){
  	if(screen.Width <= 800){
	    if($("#logo").html() == "<IMG src=\"img/fundo_br.JPG\">"){
		  $("#logo").html("<IMG src=\"img/fundo_br800.JPG\">")
		}else{
		  $("#logo").html("<IMG src=\"img/fundo_en800.JPG\">")
		}
	  $("#box").css("margin-left","5px")
	  $("#box").css("width","165px")
	  $("#box2").css("margin-left","10px")
	}
  
  	if(screen.Width < 1024){
	  $("body").css("background-image","url(\"img/fundo800.PNG\")")
	}else if(screen.Width == 1024){
	  $("body").css("background-image","url(\"img/fundo1024.PNG\")")
	}else{
	  $("body").css("background-image","url(\"img/fundo1280.PNG\")")
	}

}
	
/* function move_estrutura(aux){
	tam1 = $("#EstrutFotos table").width() + 8
	if(aux == undefined){
	  aux = tam1
	}
	if(aux > 0){
	  	if($("#EstrutFotos table").attr("class") != "parado"){
			$("#EstrutFotos table").animate({"left": "-=1px"}, 1, "linear", function(){
			  aux = aux - 1;
			  if(aux <= 0){
				  $("#EstrutFotos table").fadeOut()
				  $("#EstrutFotos table").animate({"left": "+="+tam1+"px"}, 1, function(){
					  $("#EstrutFotos table").fadeIn(function(){
						move_estrutura()
					  })
			      });
			  }
			  move_estrutura(aux)
			});
		}  
	}
}	*/

function move_estrutura(){
	tam1 = $("#EstrutFotos table").width() + 8
	$("#EstrutFotos table").animate({"left": "-="+tam1+"px"}, 80000, "linear", function(){
	  $("#EstrutFotos table").fadeOut()
	  $("#EstrutFotos table").animate({"left": "+="+tam1+"px"}, 1, function(){
		  $("#EstrutFotos table").fadeIn(function(){
			move_estrutura()
		  })
		});
	});
}	

function move_clientes(){
	tam2 = $("#ClientsLogo table").width() + 400
	$("#ClientsLogo table").animate({"left": "+=400px"}, 1, "linear", function(){
  	    $("#ClientsLogo table").fadeIn(function(){
			$("#ClientsLogo table").animate({"left": "-="+tam2+"px"}, 20000, "linear", function(){
			  $("#ClientsLogo table").fadeOut()
			  $("#ClientsLogo table").animate({"left": "+="+(tam2-400)+"px"}, 1, function(){
	 		    move_clientes()
			  });
		    })
		})
})	
}

function detectBrowser()
{
var browser=navigator.appName;
return browser; 
}


function PlaySound(url) {
document.all.sound.src = url;
}


if(window.Event) 
document.captureEvents(Event.MOUSEUP); 

function nocontextmenu() 
{ 
event.cancelBubble = true 
event.returnValue = false; 

return false; 
} 


/*
function norightclick(e) 
{ 
if(window.Event) 
{ 
if(e.which == 2 || e.which == 3) 
return false; 
} 
else 
if(event.button == 2 || event.button == 3) 
{ 
event.cancelBubble = true 
event.returnValue = false; 
return false; 
} 

} 
if(document.layers){ 
document.captureEvents(Event.MOUSEDOWN); 
} 
document.oncontextmenu = nocontextmenu; 
document.onmousedown = norightclick; 
document.onmouseup = norightclick; 
//--> 

*/