// Zobrazování podkategorií v drobečkové navigaci
jQuery(function() {
    var timeoutID;
    var subcategories$;
    var layerNum;
    var delay = 300;
    var globThis$;
    
    jQuery('.breadcrumbCategory').hover(function(e) {
        var this$ = jQuery(this);
        var currentLayerNum = this$.attr('class').substr(27);
        // nejedná se o stejnou položku jako naposledy zobrazené podkategorie?
        if (currentLayerNum != layerNum) {
            // jsou nastaveny nějaké podkategorie?
            if (subcategories$ !== undefined && timeoutID !== undefined) {
                window.clearTimeout(timeoutID);
                subcategories$.hide();
                globThis$.removeClass('activeBreadcrumbLink');
                layerNum = null;
            }

            globThis$ = this$;
            this$.addClass('activeBreadcrumbLink');
            subcategories$ = this$.next('.subcategories');
            var cClass = subcategories$.attr('class');
            var re = /numOfLists\d+/;
            if (cClass.match(re) === null) {
                subcategories$.addClass('numOfLists' + subcategories$.children('ul').size());
            }
            subcategories$.css('min-width', this$.outerWidth(true) + 20);
            
            subcategories$.show();
        } else {
            window.clearTimeout(timeoutID);
        }
    }, function(e) {
        timeoutID = window.setTimeout(function() {
            subcategories$.hide();
            globThis$.removeClass('activeBreadcrumbLink');
            layerNum = null;
        }, delay);
    });
    jQuery('.subcategories').hover(function(e) {
        window.clearTimeout(timeoutID);
    }, function(e) {
        layerNum = jQuery(this).attr('class').substr(22);
        timeoutID = window.setTimeout(function() {
            subcategories$.hide();
            globThis$.removeClass('activeBreadcrumbLink');
            layerNum = null;
        }, delay);
    });
});

