var timerID;
var menu_parent_arr = new Array();

function opacity(id, opacStart, opacEnd, millisec) {
    debug('opacity start: ' + opacStart + ' end: '+opacEnd);
    var speed = Math.round(millisec / 100);
    var timer = 0;
    var step = 10;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i-=step) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer+=step;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i+=step)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer+=step;
        }
    }
}
function changeOpac(opacity, id) { 
    //debug('changeOpac');
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
}
function hide_all() { 
    debug('hide_all');
    var count = menu_parent_arr.length;
    for (i=0; i<count; i++) {
        document.getElementById('child___'+menu_parent_arr[i]).style.display = "none";
    }
}

function submenu(item_id) {     
    debug('submenu: item_id '+item_id);
    if (document.getElementById('child___'+ item_id).style.display != "none") return; 
    hide_all();
    clearTimeout(timerID);
    document.getElementById('child___'+ item_id).style.display = ""; 
    opacity('child___'+ item_id, 0, 90, 400);
}
function submenu2(item_id) {
    debug('submenu2: item_id '+item_id);
    opacity('child___'+ item_id, 90, 0, 800);
    timerID = setTimeout("document.getElementById('child___"+ item_id +"').style.display = 'none';", 1000);
}
function settm(item_id) { 
    timerID = setTimeout("submenu2("+ item_id +");", 3000);
    debug('settm: timer ID'+timerID+' item_id '+item_id);
}
function stop_tm() { 
    clearTimeout(timerID); 
    debug('stop_tm: timer ID '+timerID);
}

function debug (str) {
    //document.getElementById('debug').innerHTML += str+'<br>';
}