/*
$(document).ready(function(){
	$("#container").after('<div id="subsubmenu"></div>');
	$("#subsubmenu").hide();
	$("#submenu ul li").each(function(){
		if($(this).children("ul").attr("tagName") != undefined){
			var el = $(this).children("ul");
			$(el).prev().mouseover(function(){
				var pos = $(this).offset();
				$("#subsubmenu").html("<ul>" + $(this).next().html() + "</ul>");
				$("#subsubmenu").css({top:pos.top - 20 + "px",left:pos.left + 170 + "px"});
				$("#subsubmenu").fadeIn("fast");
				$("#subsubmenu").mouseleave(function(){
					$("#subsubmenu").fadeOut("fast");
				});
			});
		} else {
			$(this).mouseenter(function(){
				$("#subsubmenu").fadeOut("fast");
			});
		}
	});
});
*/

$(document).ready(function () {
    $("#container").after('<div id="subsubmenu"></div>');
    $("#subsubmenu").hide();
    $("#submenu ul li").each(function () {
        if ($(this).children("ul").attr("tagName") != undefined) {
            var el = $(this).children("ul");
            $(el).prev().mouseover(function () {
                var pos = $(this).offset();
                var posY = pos.top;
                var ajusteY = 20;
                var scrollY = $(window).scrollTop();
                var janelaY = $(window).height()+scrollY;
                /* atualizar - inicio */
                $("#subsubmenu").html("<ul>" + $(this).next().html() + "</ul><div id='smbot'></div");
                /* atualizar - fim */
                var caixaY = $("#subsubmenu").height();
                if (janelaY - posY < caixaY)
                    ajusteY = 20 + caixaY - (janelaY - posY);
                $("#subsubmenu").css({ top: posY - ajusteY + "px", left: pos.left + 170 + "px" });
                $("#subsubmenu").fadeIn("fast");
                $("#subsubmenu").mouseleave(function () {
                    $("#subsubmenu").fadeOut("fast");
                });
            });
        } else {
            $(this).mouseenter(function () {
                $("#subsubmenu").fadeOut("fast");
            });
        }
    });
});
