//jquery browser plugin (required)
(function($) { $.browserTest = function(a, z) { var u = 'unknown', x = 'X', m = function(r, h) { for (var i = 0; i < h.length; i = i + 1) { r = r.replace(h[i][0], h[i][1]); } return r; }, c = function(i, a, b, c) { var r = { name: m((a.exec(i) || [u, u])[1], b) }; r[r.name] = true; r.version = (c.exec(i) || [x, x, x, x])[3]; if (r.name.match(/safari/) && r.version > 400) { r.version = '2.0'; } if (r.name === 'presto') { r.version = ($.browser.version > 9.27) ? 'futhark' : 'linear_b'; } r.versionNumber = parseFloat(r.version, 10) || 0; r.versionX = (r.version !== x) ? (r.version + '').substr(0, 1) : x; r.className = r.name + r.versionX; return r; }; a = (a.match(/Opera|Navigator|Minefield|KHTML|Chrome/) ? m(a, [[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/, ''], ['Chrome Safari', 'Chrome'], ['KHTML', 'Konqueror'], ['Minefield', 'Firefox'], ['Navigator', 'Netscape']]) : a).toLowerCase(); $.browser = $.extend((!z) ? $.browser : {}, c(a, /(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/, [], /(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/)); $.layout = c(a, /(gecko|konqueror|msie|opera|webkit)/, [['konqueror', 'khtml'], ['msie', 'trident'], ['opera', 'presto']], /(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/); $.os = { name: (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris') }; if (!z) { $('html').addClass([$.os.name, $.browser.name, $.browser.className, $.layout.name, $.layout.className].join(' ')); } }; $.browserTest(navigator.userAgent); })(jQuery);
//end plugin

(function($) {
    //área disponível
    var widthWindow;

    //largura do menu para alinhamento horizontal automático
    var widthMenu;

    //limites de posição para o menu
    var maxPos;

    function applyLayoutDetails() {
        $(".detalheHider").each(function() {
            $(this).width($(this).parent().width() - 2);
        });

        $(".col").each(function() {
            $("a:last", this).addClass("last");
        });

        $(".menuItens li:last").addClass("lastMenuItem");
    }

    function applyPngFix() {
        if ($("body").is(".msie6")) {
            $(".menuItens img").attr("src", "img/transparent.gif");
        }
    }

    function setBrowserClassName() {
        browserName = $.browser.name;
        browserVersion = ($.browser.version).split(".")[0];
        //if (browserClass == "msie") 
        $("body").addClass(browserName).addClass(browserName + "" + browserVersion);
    }

    function hideSubmenu() {
        $(".menuItens a.ativo").removeClass("ativo");
        $(".submenu:visible").hide();
        removeZIndexFix();
    }

    function zIndexFix() {
        if ($.browser.msie){//melchior
            $(".corpo").addClass("forceZIndex-1");
        }

        if ($.browser.msie && $.browser.version.indexOf("6") != -1) {
            $("select").hide();
        }
    }

    function removeZIndexFix() {
        $(".corpo").removeClass("forceZIndex-1");
        
        if ($.browser.msie && $.browser.version.indexOf("6") != -1) {
            $("select").show();
        }
    }

    $.fn.extend({
        MainMenuFNAC: function() {
            setBrowserClassName();
            applyLayoutDetails();
            applyPngFix();
            this.setMenuArea();
            this.setSubmenuAlignment();
            this.initMainMenu();
        },
        initMainMenu: function() {
            _this = this;
            $("a.menuItem").each(function() {
                $(this)
		    .mouseover(function() {

		        submenuItem = $(this);

		        target = submenuItem.attr("rel");

		        submenuItem.addClass("ativo");

		        submenuItem.parent().siblings().children().removeClass("ativo");

		        _this.showSubmenu("#submenu" + target);
		    });
            });

            $(".menuPrincipal").bind("mouseleave", function() {
                hideSubmenu();
            });

        },
        setMenuArea: function() {
            widthWindow = $(window).width();
            widthMenu = $(".menuItens ul").width();
            maxPos = 1000;
        },
        setSubmenuAlignment: function() {
            $("a.menuItem").each(function(i) {
                menuXpos = $(this).offset().left;
                target = "#submenu" + $(this).attr("rel");
                submenu = $(target);

                if (menuXpos + submenu.width() > maxPos) {
                    submenu.addClass("invertido");
                }

            }).filter(":first").parent().addClass("firstItem");
        },
        showSubmenu: function(id) {
            zIndexFix();
            $(".submenu:visible").not(id).hide();
            submenu = $(id)

            submenu.show();

            width = 0;
            $(".col", submenu).each(function() {
                width += $(this).width();
            });
            submenu.width(width);
        }
    });

})(jQuery);

$(document).ready(function() {
    $.fn.MainMenuFNAC();
});
