var tamanhoFonte = 0;

/* LIGHTBOX */
hs.align = 'center';
hs.graphicsDir = base + 'images/graphics/';
hs.transitions = ['expand', 'crossfade'];
hs.fadeInOut = true;
hs.headingEval = 'this.thumb.alt';
hs.headingOverlay.position = 'below';
hs.addSlideshow({
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .75,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

/* ANIMACAO FUNDO */
function slideSwitch() {
    var $active = $('#background img.active');
    if ( $active.length == 0 ) $active = $('#fundo img:last');

    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
   setInterval( "slideSwitch()", 12000 );
});

/* FIM ANIMACAO FUNDO */
$(document).ready(function() {

	$("#phone").mask("(99)9999-9999");
	$("#cpf").mask("999.999.999-99");
	$("#nascimento").mask("99/99/9999");
	$("#celular").mask("(99)9999-9999");
	$("#cep").mask("99999-999");

	/* INPUT */
	$("input[type='text'], textarea").each(function() {
		$(this).parent().append("<span>" + $(this).val() + "</span>");
	});
	$("input[type='text'], textarea").focus(function() {
		if($(this).val() == $(this).next("span").text()) {
			$(this).val("");
			$(this).addClass("selected");
		}
		$(this).addClass("color");
	});
	$("input[type='text'], textarea").blur(function() {
		if($(this).val() == "") {
			$(this).val($(this).next("span").text());
			$(this).removeClass("color");
		}
		$(this).removeClass("selected");
	});

	/* CANTOS ARREDONDADOS */
	$("#content-navbar li a, #subsubmenu li, span.corn, #busca-letras li, #acervo-categoria li, #acervo-periodo li, #acervo-procedencia li, #calendar h6, #filtros div, #home > div, #home > div div").corner("3px");
	$("#calendar").corner("5px");
	/* FIM CANTOS ARREDONDADOS */

	/* ULTIMO ITEM DO MENU */
	var itensMenu = $("#nav-bar > li").length;
	$("#nav-bar > li:last-child").addClass("last");
	$("#nav-bar > li").eq(itensMenu -2).addClass("last");
	$("body").find("li").eq(2).addClass("blue");

	/* FIM ULTIMO ITEM DO MENU */

	/* CORRECAO LISTA PADRAO */
	$("div.text").parent().children("ul#lista-padrao").css("min-height", "0");
	$("div#licitacoes-detalhes").parent().children("ul#lista-padrao").css("min-height", "0");
	$("div#cotacao_previa-detalhes").parent().children("ul#lista-padrao").css("min-height", "0");
	/* FIM CORRECAO LISTA PADRAO */

	/* ANIMACAO */
	$("#anim .scrollable").scrollable({circular:true, speed:1000}).autoscroll({autoplay:true, interval:10000, autopause:true });
	$("#anim + ul#nav-bar").css("margin-top", "-372px");
	/* FIM ANIMACAO */

	if ($.browser.webkit) {
		$("#nav-bar > li > a").click(function() {
			$("#nav-bar > li > ul").hide();
		});
	}
	$("#nav-bar > li > a").focus(function() {
		$("#nav-bar > li > ul").hide();
	});

	/* EBIS */
	$("#link").mouseover(function() {
		$("#ebis img").stop();
		$("#ebis img:first-child").animate({top:0, opacity: 0}, 250, function() {
			$(this).animate({top:15, opacity: 1}, 250);
			$("#ebis img + img").animate({top:35, opacity: 1}, 250);
		});
	});
	$("#link").mouseout(function() {
		$("#ebis img").stop();
		$("#ebis img + img").animate({top:45, opacity: 0}, 250);
		$("#ebis img:first-child").animate({top:0, opacity: 0}, 250, function() {
			$(this).animate({top:15, opacity: 1}, 250);
		});
	});
	/* FIM EBIS */

	/* ITENS CONTENT */
	$("#lista-padrao > li div.cursos > a, #patrocinadores > li span a").focus(function() {
		$("#lista-padrao li, #patrocinadores > li").removeClass("selected");
		$(this).parent().parent().addClass("selected");
	});
	if ($.browser.webkit) {
		$("#lista-padrao > li div.cursos > a, #patrocinadores > li span a").mousedown(function() {
			$("#lista-padrao li, #patrocinadores > li").removeClass("selected");
			$(this).parent().parent().addClass("selected");
		});
	}

	function fontes() {
		if( tamanhoFonte == -3){
			$("#eventos-left > p").css("font-size", "7px");
			$("#lista-padrao p, #mapa li, #licitacoes-detalhes > p, #shop li span, #eventos-left ul li p, #patrocinadores p, .patrocinadores-detalhes span.subtitulo, .patrocinadores-detalhes ul li, #acervo li span.subtitulo, #acervo li, #acervo-detalhes > div span.titulo, #acervo-detalhes > div span.subtitulo, #acervo-detalhes ul span.subtitulo, #acervo-detalhes ul li").css("font-size", "8px");
			$(".text p, .text a, #contato p, #obras > p, #acervo-detalhes > div p, #biblioteca-resultados span.titulo, #biblioteca-resultados span.subtitulo, #biblioteca-resultados div.text span.title").css("font-size", "9px");
			$("#lista-padrao span.titulo, #shop-detalhes span.titulo, #eventos-left h5, #obras span.titulo, #patrocinadores span.titulo, #acervo-texto, #acervo span.titulo, #acervo-detalhes > span.titulo").css("font-size", "10px");
			$("#content-text h4, #shop-detalhes > div span").css("font-size", "12px");
		};
		if( tamanhoFonte == -2){
			$("#eventos-left > p").css("font-size", "8px");
			$("#lista-padrao p, #mapa li, #licitacoes-detalhes > p, #shop li span, #eventos-left ul li p, #patrocinadores p, .patrocinadores-detalhes span.subtitulo, .patrocinadores-detalhes ul li, #acervo li span.subtitulo, #acervo li, #acervo-detalhes > div span.titulo, #acervo-detalhes > div span.subtitulo, #acervo-detalhes ul span.subtitulo, #acervo-detalhes ul li").css("font-size", "9px");
			$(".text p, .text a, #contato p, #obras > p, #acervo-detalhes > div p, #biblioteca-resultados h5, #biblioteca-resultados h6, #biblioteca-resultados div.text span.title").css("font-size", "10px");
			$("#lista-padrao span.titulo, #shop-detalhes span.titulo, #eventos-left h5, #obras span.titulo, #patrocinadores span.titulo, #acervo-texto, #acervo span.titulo, #acervo-detalhes > span.titulo").css("font-size", "11px");
			$("#content-text h4, #shop-detalhes > div span").css("font-size", "15px");
		};
		if( tamanhoFonte == -1){
			$("#eventos-left > p").css("font-size", "9px");
			$("#lista-padrao p, #mapa li, #licitacoes-detalhes > p, #shop li span, #eventos-left ul li p, #patrocinadores p, .patrocinadores-detalhes span.subtitulo, .patrocinadores-detalhes ul li, #acervo li span.subtitulo, #acervo li, #acervo-detalhes > div span.titulo, #acervo-detalhes > div span.subtitulo, #acervo-detalhes ul span.subtitulo, #acervo-detalhes ul li").css("font-size", "10px");
			$(".text p, .text a, #contato p, #obras > p, #acervo-detalhes > div p, #biblioteca-resultados span.titulo, #biblioteca-resultados span.subtitulo, #biblioteca-resultados div.text span.title").css("font-size", "11px");
			$("#lista-padrao span.titulo, #shop-detalhes span.titulo, #eventos-left h5, #obras span.titulo, #patrocinadores span.titulo, #acervo-texto, #acervo span.titulo, #acervo-detalhes > span.titulo").css("font-size", "12px");
			$("#content-text h4, #shop-detalhes > div span").css("font-size", "18px");
		};
		if( tamanhoFonte == 0){
			$("#eventos-left > p").css("font-size", "10px");
			$("#lista-padrao p, #mapa li, #licitacoes-detalhes > p, #shop li span, #eventos-left ul li p, #patrocinadores p, .patrocinadores-detalhes span.subtitulo, .patrocinadores-detalhes ul li, #acervo li span.subtitulo, #acervo li, #acervo-detalhes > div span.titulo, #acervo-detalhes > div span.subtitulo, #acervo-detalhes ul span.subtitulo, #acervo-detalhes ul li").css("font-size", "11px");
			$(".text p, .text a, #contato p, #obras > p, #acervo-detalhes > div p, #biblioteca-resultados span.titulo, #biblioteca-resultados span.subtitulo, #biblioteca-resultados div.text span.title").css("font-size", "12px");
			$("#lista-padrao span.titulo, #shop-detalhes span.titulo, #eventos-left h5, #obras span.titulo, #patrocinadores span.titulo, #acervo-texto, #acervo span.titulo, #acervo-detalhes > span.titulo").css("font-size", "13px");
			$("#content-text h4, #shop-detalhes > div span").css("font-size", "20px");
		};
		if( tamanhoFonte == 1){
			$("#eventos-left > p").css("font-size", "11px");
			$("#lista-padrao p, #mapa li, #licitacoes-detalhes > p, #shop li span, #eventos-left ul li p, #patrocinadores p, .patrocinadores-detalhes span.subtitulo, .patrocinadores-detalhes ul li, #acervo li span.subtitulo, #acervo li, #acervo-detalhes > div span.titulo, #acervo-detalhes > div span.subtitulo, #acervo-detalhes ul span.subtitulo, #acervo-detalhes ul li").css("font-size", "12px");
			$(".text p, .text a, #contato p, #obras > p, #acervo-detalhes > div p, #biblioteca-resultados span.titulo, #biblioteca-resultados span.subtitulo, #biblioteca-resultados div.text span.title").css("font-size", "13px");
			$("#lista-padrao span.titulo, #shop-detalhes span.titulo, #eventos-left h5, #obras span.titulo, #patrocinadores span.titulo, #acervo-texto, #acervo span.titulo, #acervo-detalhes > span.titulo").css("font-size", "15px");
			$("#content-text h4, #shop-detalhes > div span").css("font-size", "22px");
		};
		if( tamanhoFonte == 2){
			$("#eventos-left > p").css("font-size", "12px");
			$("#lista-padrao p, #mapa li, #licitacoes-detalhes > p, #shop li span, #eventos-left ul li p, #patrocinadores p, .patrocinadores-detalhes span.subtitulo, .patrocinadores-detalhes ul li, #acervo li span.subtitulo, #acervo li, #acervo-detalhes > div span.titulo, #acervo-detalhes > div span.subtitulo, #acervo-detalhes ul span.subtitulo, #acervo-detalhes ul li").css("font-size", "13px");
			$(".text p, .text a, #contato p, #obras > p, #acervo-detalhes > div p, #biblioteca-resultados span.titulo, #biblioteca-resultados span.subtitulo, #biblioteca-resultados div.text span.title").css("font-size", "15px");
			$("#lista-padrao span.titulo, #shop-detalhes span.titulo, #eventos-left h5, #obras span.titulo, #patrocinadores span.titulo, #acervo-texto, #acervo span.titulo, #acervo-detalhes > span.titulo").css("font-size", "18px");
			$("#content-text h4, #shop-detalhes > div span").css("font-size", "25px");
		};
		if( tamanhoFonte == 3){
			$("#eventos-left > p").css("font-size", "13px");
			$("#lista-padrao p, #mapa li, #licitacoes-detalhes > p, #shop li span, #eventos-left ul li p, #patrocinadores p, .patrocinadores-detalhes span.subtitulo, .patrocinadores-detalhes ul li, #acervo li span.subtitulo, #acervo li, #acervo-detalhes > div span.titulo, #acervo-detalhes > div span.subtitulo, #acervo-detalhes ul span.subtitulo, #acervo-detalhes ul li").css("font-size", "15px");
			$(".text p, .text a, #contato p, #obras > p, #acervo-detalhes > div p, #biblioteca-resultados span.titulo, #biblioteca-resultados span.subtitulo, #biblioteca-resultados div.text span.title").css("font-size", "18px");
			$("#lista-padrao span.titulo, #shop-detalhes span.titulo, #eventos-left h5, #obras span.titulo, #patrocinadores span.titulo, #acervo-texto, #acervo span.titulo, #acervo-detalhes > span.titulo").css("font-size", "20px");
			$("#content-text h4, #shop-detalhes > div span").css("font-size", "28px");
		};
	};
	$('.text-more').click(function() {
		tamanhoFonte++;
		fontes();
	});
	$('.text-less').click(function() {
		tamanhoFonte--;
		fontes();
	});
	/* FIM ITENS CONTENT */

	$('.news ul.error a').live("click", function() {
		var item = $(this).attr("class");
		$("#" + item).focus();
	});
	if ($.browser.webkit) {
		$('.news ul.error a').live("keydown", function() {
		var item = $(this).attr("class");
		$("#" + item).focus();
	});
	}

	/* pesquisa biblioteca by MC Carbonera */

	/*$('.btnEnviar').live("click", function() {
		var params = $("#biblioteca-autor").serialize();
            $.ajax({
              type: 'GET',
              url: 'http://biblioteca.mam.org.br/api/',
			  dataType: 'jsonp',
              data: params,
			  beforeSend: function(){alert('buscando');},
			  complete:   function(){alert('ok');},
			  success: 	function(data){
							alert(data);
						}
            });
	});
	*/

	/* fim pesquisa */
});

/* FUNÇÃO QUE DETERMINA AS EXPRESSÕES REGULARES DOS OBJETOS */
	function leech(v) {
		v = v.replace(/o/gi, "0")
		v = v.replace(/i/gi, "1")
		v = v.replace(/z/gi, "2")
		v = v.replace(/e/gi, "3")
		v = v.replace(/a/gi, "4")
		v = v.replace(/s/gi, "5")
		v = v.replace(/t/gi, "7")
		return v
	}

	var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	function doEmail(pStr) {
		eval("reEmail = reEmail3");
		if (reEmail.test(pStr)) {
			return true;
		} else {
			return false;
		}
	}

/* VALIDACAO FALE CONOSCO */
	function validaNews() {
		var valido = true;

		if ($(".news input[name='name']").val() == "") {
			$(".news input[name='name']").addClass("error");
			valido = false;
			$("ul.error").append("<li class='name'><a href='javascript:;' class='FormName'>Voc&ecirc; Precisa Informar seu nome!</a></li>");
		} else {
			$(".news input[name='name']").removeClass("error");
			$("ul.error").remove("li.name");
		};

		if($(".news input[name='email']")[0]){
			if ($(".news input[name='email']").val() == "") {
				$(".news input[name='email']").addClass("error");
				valido = false;
				$("ul.error").append("<li class='email'><a href='javascript:;' class='FormEmail'>Por favor informe um e-mail v&aacute;lido!</a></li>");
			} else if(!doEmail($("input[name='email']").val())) {
				$(".news input[name='email']").addClass("error");
				$("ul.error").append("<li class='email'><a href='javascript:;' class='FormEmail'>Por favor informe um e-mail v&aacute;lido!</a></li>");
				valido = false;
			} else {
				$(".news input[name='email']").removeClass("error");
				$("ul.error").remove("li.email");
			}
		};

		if (valido) {
			$("ul.error li").remove();
		} else {

		};

		return valido;
	};



