// JavaScript Document
$(document).ready(function() {	
	var abb	= $("body").height();
	var ebb = eval(abb)*(66/100);
	if(ebb < 526) {
		$(".header").css({
			"min-height": 365+142+"px",
			"max-height": ebb+142+"px"
		})
		$(".banner").css({
			"min-height": "365px",
			"max-height": ebb+"px"
		})
	} else {
		$(".header").css({
			"min-height": 365+142+"px",
			"max-height": 526+142+"px"
		})
		$(".banner").css({
			"min-height": "365px",
			"max-height": 526+"px"
		})
	}
	
	$('a.logo').hover(function() {
		$(this).stop().fadeTo(600, 0.6);
	}, function() {
		$(this).stop().fadeTo(600, 1.0);
	});
	
	$("#slider").bxSlider({
		displaySlideQty: 4,
		moveSlideQty: 1
	});
	
	$(".bx-wrapper").css("margin", "auto");
	
	$("a[rel='box']").hover(function() {
		$(this).find("img").stop(true, true).fadeTo("fast", 0.8);
	}, function() {
		$(this).find("img").stop(true, true).fadeTo("fast", 1.0);
	});
	
	$("a[rel='submit'], [name='button']").hover(function() {
		$(this).stop().fadeTo(400, 0.8);
	}, function() {
		$(this).stop().fadeTo(400, 1.0);
	});
	
	$("[rel='webmail']").click(function() {
		if($(".loginDiv").height() < 1) {
			$(".loginDiv").stop(true,true).animate({"height": "130px"}, 200);
			$(".background").stop(true,true).animate({"top": "271px"}, 200);
			$("#formLogin").stop(true,true).delay(200).fadeIn(100);
			return false;
		} else {
			$("#formLogin").stop(true,true).fadeOut(100);
			$(".background").stop(true,true).delay(100).animate({"top": "141px"}, 200);
			$(".loginDiv").stop(true,true).delay(100).animate({"height": "0px"}, 200);
			return false;
		}
	});
	
	$("[rel='fechar']").click(function() {
		$("#formLogin").stop(true,true).fadeOut(100);
		$(".background").stop(true,true).delay(100).animate({"top": "141px"}, 200);
		$(".loginDiv").stop(true,true).delay(100).animate({"height": "0px"}, 200);
		return false;
	});
	
	$("a[rel='acessar']").click(function() {
		enviarForm()
		return false;
	});
	
	function enviarForm() {
		var canSubmit = true;
		$("#formLogin .text").each(
			function(){
				if ($(this).val() == ""){
					canSubmit = false;
					$(this).addClass("Error");
				}
			}
		);
		if(canSubmit == false) {
			return canSubmit;
		}
		if(canSubmit == true) {
			document.formLogin.submit();
		}
			
	}
	$("#formLogin .text").focus(function() { $(this).removeClass("Error"); });
	
	$(".linha span").click(function() {
		$(this).parent().find("input, textarea").focus();
	});
	$(".linha .text, .linha .message").focus(function() {
		$(this).parent().find("span").removeClass("vazio").fadeOut(1);
	});
	$(".linha .text, .linha .message").blur(function() {
		if($(this).val() == "" || $(this).val() == "(__) ____-____") {
			$(this).parent().find("span").fadeIn(1);
		}
	});
	
	$(".submit").click(function() {
		validaCadastro();
		return false;
	});
	function validaCadastro() {	
		var submitCadastro = true
		$("#formCadastra .text").each(function() {
			if($(this).val() == "") {
				$(this).next().addClass("vazio");
				submitCadastro = false
			}
		});
		if(submitCadastro == false) {
			return submitCadastro;
		}
		if(submitCadastro == true) {
			gravar("formCadastra", "cadastra_email.php?");
		}
	}
});

$(window).resize(function() {
	var abb	= $("body").height();
	var ebb = eval(abb)*(66/100);
	if(ebb < 526) {
		$(".header").css({
			"min-height": 365+141+"px",
			"max-height": ebb+141+"px"
		})
		$(".banner").css({
			"min-height": "365px",
			"max-height": ebb+"px"
		})
	} else {
		$(".header").css({
			"min-height": 365+142+"px",
			"max-height": 526+142+"px"
		})
		$(".banner").css({
			"min-height": "365px",
			"max-height": 526+"px"
		})
	}
	var acc = $(".banner img:last").height();
	var ecc = eval(acc)*(40/100);
	$(".banner img:last").css("margin", "-"+ecc+"px 0 0 0");
});
