(function($) {
    $(function() {
        $('#nav0-1 > a').hover(function() {
            $('.submenu').css('display', 'none');

            var linkHeight = parseInt($(this).next('.submenu').find('.wrapper').find('a').css('height')) + (parseInt($(this).next('.submenu').find('.wrapper').find('a').css('padding-top')) * 2);
            var linkAmount = $(this).next('.submenu').find('.wrapper').find('a').length;

            var leftPadding = $(this).position().left;

            $(this).next('.submenu').css({
                'display': 'block',
                'left': leftPadding
            }).data('hover',false);

        },function(){
            var that = this;
            window.setTimeout(function(){
                var $subMenu = $(that).next('.submenu');
                if( $subMenu.data('hover') != true )
                {
                    $subMenu.data('hover',false);
                    $subMenu.css('display', 'none');
                }
            },50);
        });

        $('.submenu').hover(function(){
            $(this).data('hover',true);
        },function(){
            $(this).data('hover',false);
            $(this).css('display', 'none');
        });
    });
})($j);
