$(function(){

    var smart = true;
    var timer, thisLast, thisNext, lastX;
    
    $('#categoryList').mouseleave(function(){
        if (timer) {
            clearTimeout(timer);
            timer = null;
        }
        $.browser.msie &&  $('ul.categoryBalloon:visible').hide();                // hide()
        $.browser.msie ||  $('ul.categoryBalloon:visible').fadeOut('false');      // fadeOut()
        thisLast = thisNext = null;
    });
    
    $('#categoryList > li').mouseenter(function(e){
        if (thisNext != this && timer) {
            clearTimeout(timer);
            timer = null;
        }
        if (thisLast == this) {
            return;
        }
        thisNext = this;
        if (!smart || !thisLast || Math.abs(lastX-e.pageX) < 5)                // 5px
            show();                                                            // quick
        else
            timer = setTimeout(show, 300);                                    // 0.3s
        lastX = e.pageX;
        
        function show(){
            $('#categoryList > li > ul.categoryBalloon:visible').hide();     // hide()
            if ($('ul.listOpen', thisNext).length == 0) {
                $('ul.categoryBalloon', thisNext).show();                     // show()
            }
            thisLast = thisNext;
        }
    });
});


function categorymenuOpen(categoryID) {
    var category = categoryID.match(/^list/) ? ('#'+categoryID): ('#list'+categoryID.substr(0,1));    // listB or B2

    $(category).css('height','auto');
    $('ul.sideList', category).appendTo(category).addClass('listOpen');

    $(category).find('#'+categoryID).find('a').css({ color:'#999999', 'text-decoration':'none' });    // gray
}

function categorymenu10Open(categoryID) {
    var category = categoryID.match(/^list/) ? ('#'+categoryID): ('#list'+categoryID.substr(0,3));    // listB or B2

    $(category).css('height','auto');
    $('ul.sideList', category).appendTo(category).addClass('listOpen');

    $(category).find('#'+categoryID).find('a').css({ color:'#999999', 'text-decoration':'none' });    // gray
}

