
	$(document).ready(function(){
					
		/* Faz o efeito do logo trocando as classes */
		var elemento = "h1 a";
		var velocidade = 350;
		$(elemento).css("background","url(/site/imagens/themeTorriton/logo.png) no-repeat");
		$(elemento).hover(function(){
			$(elemento).fadeOut(velocidade,function(){ 
				$(elemento).css("background","url(/site/imagens/themeTorriton/esfera.png) no-repeat").fadeIn(velocidade);
			});
		},function(){
			$(elemento).fadeOut(velocidade,function(){ 
				$(elemento).css("background","url(/site/imagens/themeTorriton/logo.png) no-repeat").fadeIn(velocidade);
			});
		});
		
				
		/* Troca as imagens do header ao passear pelo menu */
		alterarImagem("menuHome","0 0");
		alterarImagem("menuQuem","-275px 0");
		alterarImagem("menuSalao","-550px 0");
		alterarImagem("menuCentro","-825px 0");
		alterarImagem("menuCasamento","-1100px 0");
		alterarImagem("menuFormatura","-1350px 0");
		alterarImagem("menuDebutante","-1650px 0");
		alterarImagem("menuLojas","-1925px 0");
		alterarImagem("menuValet","-2200px 0");
		alterarImagem("menuLocalizacao","-2475px 0");
		
		/* Habilita o hover no menu para IE6 */ 
		function mainmenu(){
			$(" #nav ul ul").css({ display: "none" });
			$(" #nav ul li").hover(function() {
				$(this).find('ul:first').css({ visibility: "visible", display: "block" });
			}, function() {
				$(this).find('ul:first').css({ visibility: "hidden", display: "none" });
			});
		}
		mainmenu();
		
		/* Atribui a classe "ativo" ao navegar pelos sub-menus */
		$("#nav li.categoria").hover(function(){
			$(this).children("a").addClass("ativo");
		}, function() {
			$(this).children("a").removeClass("ativo");
		});
		
		$("#menuSuperior li.categoria").hover(function(){
			$(this).children("a").addClass("ativo");
		}, function() {
			$(this).children("a").removeClass("ativo");
		});
		
		
		/* Função para acessibilidade dos menus drop-down */
		function habilitaSubMenus() {
			var lis = document.getElementsByTagName('li');
			for (var i = 0, li; li = lis[i]; i++) {
				var link = li.getElementsByTagName('a')[0];
				if (link) {
					link.onfocus = function() {
						var ul = this.parentNode.getElementsByTagName('ul')[0];
						if (ul)
							with (ul.style) { display = 'block'; visibility = 'visible'; }
					}
					var ul = link.parentNode.getElementsByTagName('ul')[0];
					if (ul) {
						var ullinks = ul.getElementsByTagName('a');
						var ullinksqty = ullinks.length;
						var lastItem = ullinks[ullinksqty - 1];
						if (lastItem) {
							lastItem.onblur = function() {
								with (this.parentNode.parentNode.style) { display = 'none'; visibility = 'hidden' }
							}
						}
					}
				}
			}
		}
		
		/* Executa a função "habilitaSubMenus" */
		habilitaSubMenus();
		
		/* Monta as abas de notícias da home */
		$('#noticias > ul').tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 7000);
		
		/* Valida o form de contato */
		$(".mailContato").validate({
			errorLabelContainer:"#boxErros",
			wrapper: "li",
			rules:{
				txNome:{
					required:true,
					minlength: 2
				},
				txEmail:{
					required:true,
					email:true
				},
				txTelefone:{
					required:true,
					equalTo:"(__)____-____"
				},
				txMensagem:{
					required:true
				}
			},
			messages:{
				txNome:{
					required: "- Digite o seu nome",
					minlength: "- O seu nome deve conter, no mínimo, 2 caracteres"
				},
				txEmail:{
					required: "- Digite o seu e-mail",
					email: "- Digite um e-mail válido"
				},
				txTelefone:{
					required: "- Digite seu telefone",
					equalTo: "- Digite seu telefone"
				},
				txMensagem:{
					required: "- Digite a sua mensagem"
				}
			}
		});
		
		// Insere máscaras nos inputs
		$("#txTelefone").mask("(99)9999-9999");

	});
	
	//fecha com o esc
	$(document).keydown(function(event){
		if(event.keyCode == 27) fechar();
	});
	
	function fechar(){
		$('#nav ul ul').css({visibility:"visible", display:"none"});
	}
	
    /* Função para limpar textos de inputs */
    function limparTextoInput(campo, valor) {
        if (document.getElementById(campo).value == "") {
            document.getElementById(campo).value = "" + valor + "";
        }
    }
    function voltarTextoInput(campo, valor) {
        if (document.getElementById(campo).value == "" + valor + "") {
            document.getElementById(campo).value = "";
        }    }
	
	function alterarImagem(id,coord){
		$("#"+ id +"").nextAll().andSelf().hover(function(){
			$("#header .coluna-2").css("background-position",""+ coord +"");
		}, function() {
			$("#header .coluna-2").css("background-position","0 0");
		});
	}
