// JavaScript Document

var blocoAtivo = "sinpopseCont";
var enable = false;
var inputCont = "";


$(document).ready(function(){

	/* LIGHT BOX */
	$('a[name=modal]').click(function(e) {
        e.preventDefault();

        var id = $(this).attr('href');

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        var winH = $(window).height();
        var winW = $(window).width();
		

        //$(id).css('top', winH / 2 - $(id).height() / 2);
		$(id).css("top", ($(window).height() / 2) + $(window).scrollTop() - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

		
        $(id).fadeIn(2000);
		
		

    });

    $('.fecharModal').click(function() {
        var id = $(this).attr('href');
        $('#mask').hide();
        $(id).hide();
    });
	
	
	/*  TOOLTIP */
    $(".boxListagemTop .livroListagem .livroItem span a").tooltip({
		bodyHandler: function() {return $($(this).parent().prev()).html();},
		showURL: false
	});
	
	
	/*  LIGHTBOX IMAGEM */
	$('a[name=ampliar]').lightBox({ fixedNavigation: true });
	
	
	/*  ABAS */
	$(".detalhes_abas li span a").click(function() {
		var bloco = $(this).attr('rel');
		
		if (blocoAtivo != bloco) {
			$("." + blocoAtivo).hide();
			$("a[rel=" + blocoAtivo + "]").parent().parent().removeClass('aba_on');
		 	$("." + bloco).show();
		 	$(this).parent().parent().addClass('aba_on');
		 	blocoAtivo = bloco;
		}
	});
	
	/* CADASTRO */
	$("label:contains('*CPF:')").next('input').mask("999.999.999-99");
	$("label:contains('*CNPJ:')").next('input').mask("99.999.999/9999-99");
	$("label:contains('*IE:')").next().next().click(
		function (){
			
			if(!enable){
				$(this).prev().removeAttr("disabled");
				$(this).prev().val(inputCont);
				$(this).prev().focus();
				enable = true;
			}
			else
			{
				$(this).prev().attr("disabled","disabled");
				inputCont = $(this).prev().val();
				$(this).prev().val('');
				$(this).prev().blur();
				enable = false;
				
			}

		 }
	 );
	

});





