var L1, L2; // timeouts for the currently active nav folder
var timeout=500;

function deFocus() {
    clearTimeout(L2);
    clearTimeout(L1);
}

function level1Focus(elem) {
    if ($(elem).attr("id") == 'ACTIVE_L_1') return;
    clearTimeout(L1);
    L1=setTimeout(function(){level1Nav(elem)},timeout);
}

function level2Focus(elem) {
    if ($(elem).attr("id") == 'ACTIVE_L_2') return;
    clearTimeout(L2);
    L2=setTimeout(function(){level2Nav(elem)},timeout);
}

function level1Nav(elem) {
    if ($(elem).attr("id") == 'ACTIVE_L_1') return; // if this toplevel nav is already open, do nothing (don't close and reopen).

    //set any previously active top level nav as inactive
    $('.active').removeClass('active');
    jQuery("#ACTIVE_L_2").attr("id", "");
    jQuery("#ACTIVE_L_3").attr("id", "");
    if ($(elem).next().children('li').length>0) {
        $(elem).addClass('active');
    }

    jQuery("#ACTIVE_L_1").attr("id", "");
    // set the current nav as our top level via id attribute,
    jQuery(elem).attr("id", "ACTIVE_L_1");
    //$(elem).attr('id')='active';
    $('.level_3').slideUp(timeout/2);
    $('.level_2').slideUp(timeout/2);
    $(elem).next().children('.level_2').slideDown();

}
function level2Nav(elem) {
    if ($(elem).attr("id") == 'ACTIVE_L_2') return;

    //set any previously active second level nav as inactive
    $('#ACTIVE_L_2').removeClass('active');
    $('#ACTIVE_L_3').removeClass('active');
    if ($(elem).next().children('li').length>0) {
        $(elem).addClass('active');
    }
    jQuery("#ACTIVE_L_2").attr("id", "");
    // set the current nav as our second level via id attribute,
    jQuery(elem).attr("id", "ACTIVE_L_2");
    $('.level_3').slideUp(timeout/2);
    $(elem).next().children('.level_3').slideDown();
}


