var tm_section_id = 0;
var tm_section_status = 0;
var tm_timeout_id;
var tm_sections_array = new Array();

function tm_get_element(id) {
    var xid;
    var elm;
    xid = 'tm-'+id;
    if (document.all)  {
        elm = document.all(xid);
    } else if (document.getElementById) {
        elm = document.getElementById(xid);
    } else if (document.layers) {
        elm = document.layers[xid];
    } else {
        elm = null;
    }
    return elm;
}

function tm_init_menu() {
    var i = -1;
    do {
        i++;
        tm_sections_array[i] = tm_get_element(i);
        if (tm_sections_array[i] != null) {
            tm_sections_array[i].style.display='none';
        }
    } while (tm_sections_array[i]);
}

function tm_hide_menu() {
    var i = 0;
    while (tm_sections_array[i]) {
        tm_sections_array[i].style.display='none';
        i++;
    }
}

function tm_section_on_now(xtmp_section_id) {
        tm_section_id = xtmp_section_id;
        tm_section_status = 1;
        tm_section_show();
}

function tm_menu_on() {
    if (tm_section_status == 3) {
        clearTimeout(tm_timeout_id);
        tm_section_status = 2;
   }
}

function tm_menu_off() {
    if (tm_section_status == 2) { // zobrazuje se za chvili se ma smazat
        tm_section_status = 3;
        tm_timeout_id = setTimeout('tm_section_hide()',300);
    }
}

function tm_section_off() {
    if (tm_section_status == 2) { // zobrazuje se za chvili se ma smazat
        tm_section_status = 3;
        tm_timeout_id = setTimeout('tm_section_hide()',300);
    } else if (tm_section_status == 1) { // mel se ukazat ale to uz je pase
        clearTimeout(tm_timeout_id);
        tm_section_status = 0;
    }
}

function tm_section_on(xtmp_section_id) {
    if (tm_section_status == 0) {
        tm_section_status = 1;
        tm_section_id = xtmp_section_id;
        tm_timeout_id = setTimeout('tm_section_show()',150);
    } else if (tm_section_status == 3) {
        clearTimeout(tm_timeout_id);
        if ( tm_section_id == xtmp_section_id) {
            tm_section_status = 2;
        } else {
            tm_section_id = xtmp_section_id;
            tm_section_status = 1;
            tm_section_show();
        }
    }
}

function tm_section_show() {
    if (tm_section_status == 1) {
        tm_hide_menu();
        tm_sections_array[tm_section_id].style.display='block';
        tm_section_status = 2;
    }
}

function tm_section_hide() {
    if (tm_section_status == 1) {
        tm_section_status = 0;
    } else if (tm_section_status == 3) {
        tm_hide_menu();
        tm_section_status = 0;
    }
}
