$(document).ready(function() {
    $("a[rel='external']").attr('target', '_blank');

    if ($("#faq").length) {
        $("#faq ul.questions li:odd").addClass("odd");
    }

    if ($("body#news").length) {
        $("div.news-images a:not(:first)").hide();
        if ($("div.news-images a").length > 1) {
            $("div.news-images").append("<a href='' class='see-more'>veja mais fotos</a>").find(".see-more").attr("href", "javascript:void(0)").click(function() {
                $("div.news-images a:first").next().click();
            });
        }
        $("div.news-images a:not(.see-more)").lightBox({
            txtImage: "Foto",
            txtOf: "de"
        });
    }

    if ($("#simulator-first-step").length) {
        $("input[name='valor']:not(:checked)").parent().siblings("input.text-field").attr("disabled", true);
        $("input[name='valor']").click(function() {
            $("input[name='valor']:not(:checked)").parent().siblings("input.text-field").attr("disabled", true).attr("value", "0");
            $(this).parent().siblings("input.text-field").attr("disabled", false);
        });
    }

    if ($("#simulator-second-step").length) {
        $('table.result tr:odd').addClass('odd');
    }


    if ($("#all-news, #news").length) {
        $(".highlight:last-child").addClass("last");
        $(".other-news li:odd").addClass("odd");
    }
    if ($("body#contact-us")) {
        if ($("#ouvidoria").length) {
            $("#ouvidoria").click(function() {
                $("#contact-options").slideDown("slow");
                $("#this").unbind("click");
            })
        } else {
            $("#contact-options").show();
        }
    }
    $(".decrease").click(function() { fontSize("minus") }).blur(); //blur() aqui remove o foco do elemento, logo após o clique
    $(".increase").click(function() { fontSize("plus") }).blur();
});

function changeBodyClass(cssClass) {
	$("body").removeAttr('class').addClass(cssClass);
	return(false);
}

function calculate() {
	$("input[name='percent']").each(function() {
		var value = $(this).parents('tr').find('span.valorLance');

		if ($(this).val()) {
			var idCota = $(this).parents('tr').find('input[name="idCotas"]').val();
			var numeroGrupos = $(this).parents('tr').find('input[name="numeroGrupos"]').val();
			var dataAssembleias = $(this).parents('tr').find('input[name="dataAssembleias"]').val();
			var numeroCotas = $(this).parents('tr').find('input[name="numeroCotas"]').val();

			value.load(rootUrl + "bid/calculate", { idCota: idCota, percent: $(this).val(), numeroGrupo: numeroGrupos, numeroCota: numeroCotas, dataAssembleia: dataAssembleias }, function(response) {
				$(this).html("R$ " + response);
			});
		} else {
			value.html("");
		}
	});
}

function fontSize(action, container){
    container = typeof(container) != 'undefined' ? container : "#content" //se não for especificado um container será "div.texto"
    
	baseSize = parseInt($(container+" p").css("font-size")) //extraímos o font-size padrão, tomando como base o p do nosso container
	
	
 
    $els = $(container+" p");
 
    $els.each(function(){
        $fs = parseInt($(this).css("font-size"));
        if(action=="plus" && baseSize < 16){ 
            $fs+=1;
        }
        else if(
            action == "minus" && baseSize > 11) {
        $fs -= 1;
               }
        $(this).css("font-size", $fs)
    })
}