if (!/^http:\/\/www.bhnight.net(.*)$/.test(window.location.href)) {
	caminho = window.location.href.match(/bhnight.net(.*)$/);
	window.location.href = 'http://www.bhnight.net' + caminho[1];
}

aguardarLogar = false;
function logar () {
	if (aguardarLogar == false) {
		aguardarLogar = true;
		exibeAlerta("Enviando... Aguarde...");
		pageTracker._trackPageview("/logar");
		$.post("logar", {email: $("#loginEmail").val(), senha: $("#loginSenha").val()}, function (data) {
				if (data == true) {
					window.location.href = window.location.href;
				} else if (data == "ativar") {
					exibeAlerta ("Seu cadastro não está ativado!<br /><br /><a href='ativar'>Clique aqui para ativar seu cadastro.</a>");
					aguardarLogar = false;
				} else if (data == "email") {
					exibeAlerta ("E-mail inválido!");
					aguardarLogar = false;
				} else if (data == "senha") {
					exibeAlerta ("Senha incorreta!<br /><br /><a href='recuperar-senha'>Clique aqui para recuperar sua senha.</a>");
					aguardarLogar = false;
				} else {
					exibeAlerta ("Erro inexperado! Tente novamente mais tarde.");
					aguardarLogar = false;
				}
			}
		);
	} else {
		exibeAlerta("Enviando... Aguarde...");
	}
	return false;
}

$(document).ready(function(){

	criaPublicidadeTopo();
	
	$("#loginEmail").focus(function(){
		if ($(this).val() == 'e-mail') {
			$(this).val('');
		}
	}).blur(function(){
		if ($(this).val().length == 0) {
			$(this).val('e-mail');
		}
	});
	
	$("#loginSenha").focus(function(){
		if ($(this).val() == 'senha') {
			$(this).val('');
		}
	}).blur(function(){
		if ($(this).val().length == 0) {
			$(this).val('senha');
		}
	});
	
	$("#sub-menu-barra").bind("mouseenter",function(){
		n = $("#sub-menu-barra").queue("fx");
		$("#painel").stop().animate({ 
        	height: "120px",
        	opacity: 1
        }, 200);
    }).bind("mouseleave",function(){
    	$("#painel").stop().animate({ 
        	height: 0,
        	opacity: 0
        }, 500);
    });
    
	$("div.evento").bind("mouseenter",function(){
		$("img.imagem", this).addClass("imagemHover");
		$("p.descricao", this).addClass("descricaoHover");
    }).bind("mouseleave",function(){
    	$("img.imagem", this).removeClass("imagemHover");
    	$("p.descricao", this).removeClass("descricaoHover");
    }).click(function(){
    	window.location.href = $("a", this).attr("href");
    });
    
	$("div.evento-mini").bind("mouseenter",function(){
		$("p.descricao", this).addClass("descricaoHover");
    }).bind("mouseleave",function(){
    	$("p.descricao", this).removeClass("descricaoHover");
    }).click(function(){
    	window.location.href = $("a", this).attr("href");
    });
    
    $('#newsletter').submit(function(){
    
    	if (/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/.test($('#newsEmail').val())) {
    
	    	exibeAlerta('Enviando... Aguarde...');
	    	
	    	pageTracker._trackPageview("/newsletter/adicionar");
	    	$.post(
		    	'newsletter/adicionar',
		    	{ email: $('#newsEmail').val() },
		    	function (data) {
		    		if (data == true) {
		    			exibeAlerta('<strong>Ok! O e-mail ' + $('#newsEmail').val() + ' está no newsletter.</strong>');
		    			$('#newsEmail').val('e-mail');
		    		} else {
		    			exibeAlerta('Ops, houve algum erro no servidor. =(<br />Por favor tente novamente mais tarde.');
		    		}
		    	}
	    	);
	    	
	    } else {
	    	exibeAlerta('E-mail inválido!<br />Verifique o e-mail e tente novamente.');
	    }
	    
    	return false;
    	
    });
    
    $('#newsEmail').focus(function(){
		if ($(this).val() == 'e-mail') $(this).val('');
	}).blur(function(){
		if ($(this).val() == '') $(this).val('e-mail');
	});
    
});

function criaPublicidadeTopo () {
	$("#publicidadeTopo").mouseover(function() {
		$("#publicidadeTopo").removeClass("fechado").addClass("aberto");
    }).mouseout(function() {
		$("#publicidadeTopo").removeClass("aberto").addClass("fechado");
    });
}

function fechaPublicidadeCapa () {
	$("#publicidadeCapa").hide();
}

function exibeAlerta (mensagem) {
	$("#alertas").html('<div class="fundo"></div><div class="mensagem"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><p>'+mensagem+'</p><p style="margin-top: 10px; font-size: 12px;"><a href="javascript:void(0);" onclick="fechaAlerta();">fechar</a></p></td></tr></table></div>');
	$("#alertas .fundo").fadeTo(500, 0.8);
	$("#alertas .mensagem").fadeTo(800, 1);
}

function fechaAlerta () {
	$("#alertas").html('');
}
