var Portal = {
    init: function() {
        this.toggleMenu();
    },
    /*
    Método dá um 'toggle' em todos os níveis do menu principal 
    @author: Evandro L. Gonçalves
    @return void
    */
    toggleMenu: function() {
        $(".menuServicos li").hover(
			function() {
			    if ($(this).is(".menuTtl")) {
			        $(this).addClass("atv");
			    }


			    $(this).find("> .sub").show();

			    // Ajusta a posição do box referente ao veículo de acordo com o tamanho da janela
			    if ($(this).find("> .sub").hasClass("subMenuCarros")) {
			        var alturaCarro = $(this).find("> .sub").height();
			        var posTopCarro = $(this).find("> .sub").offset().top;
			        var totalCarro = posTopCarro + alturaCarro;
			        var alturaBody = $(window).height();

			        if (totalCarro > alturaBody) {
			            var topCarro = totalCarro - alturaBody;
			            $(this).find("> .sub").css("top", "-" + topCarro + "px");
			        }
			    }
			},

			function() {
			    $(this).find(".sub").hide();

			    if ($(this).parent().find(".subMenu1").is(".subMenu1")) {
			        $(".menuServicos .menuTtl").removeClass("atv");
			    }
			}
		);
    }
}

$(document).ready(function() {
    Portal.init();
});
