$(document).ready(function () {

    $('#topNavigation ul.root li.static a').each(function () {
        /* positioning text to topmenu bottom line 
        NOTE: adjust the distance from bottom in css class:
        .s4-tn LI.static > .menu-item 
        */
        var topMargin = $(this).css('height', 'auto').parent().height() - ($(this).height() + parseInt($(this).css('padding-bottom')));
        $(this).css('margin-top', topMargin + 'px');
    });
    $('#topNavigation ul.root li.static').each(function () {
        // fix widths of the top navigation
        $(this).find('a .menu-item-text').wrapInner('<span />');
        var linkTextWidth = $(this).find('a .menu-item-text span').width();
        var linkLRPadding = parseInt($(this).find('a').css('padding-left')) + parseInt($(this).find('a').css('padding-right'));
        linkLRPadding += parseInt($(this).find('a').css('border-left-width')) + parseInt($(this).find('a').css('border-right-width'));
        var liNewWidth = linkTextWidth + linkLRPadding;
        $(this).css('width', liNewWidth + 'px');
    });
    $('#secondLevelNavContainer div div ul li').reverseOrder();
    $('#secondLevelNavContainer div div ul li:last').addClass('first');

});
