//==============================================================================
//  MENU SCRIPT 
//==============================================================================
//  obfuscator-ignore-functions: m_on|m_off|_hide_all
//  obfuscator-ignore-variables: menustyle|menu_start_depth|menu_max_class_depth
//==============================================================================

//  public variables
var menu_start_depth = 0;       // offset to apply when assigning classes
var menu_max_class_depth = 0;   // max depth for which classes are assigned

//  private variables
var _menu_debug         = false;
var _menu_locktree      = new Array();
var _menu_item_parents  = new Array();
var _menu_timer         = false;

function m_on(id, parent)
{
//  store item parents (only needed to restore stylesheets)
    _menu_item_parents[id] = parent;
    
//  clear timer if it's active
    if(false !== _menu_timer) {
        clearTimeout(_menu_timer);
        _menu_timer = false;
    }
    
//  hide all subitems beyond this parent
    while(last_parent = _menu_locktree.pop()) {
        if(parent == last_parent) {
            _menu_locktree.push(parent);
            break;
        } else {
            _hide_submenu(last_parent,_menu_locktree.length);
        }
    }
    
    _menu_locktree.push(id);
    
    _show_submenu(id, parent, _menu_locktree.length-1);
    _show_menu_debug();
}

function m_off(id, parent)
{
    if(false !== _menu_timer) {
        clearTimeout(_menu_timer);
        _menu_timer = false;
    }
    _menu_timer = setTimeout('_hide_all()',500);
}

function _hide_submenu(id,depth)
{
    var menuitem = document.getElementById('item_'+id);
    menuitem.className = 'fp_menuitem fp_menuitem_'+Math.min(menu_max_class_depth,depth+menu_start_depth);
   
//  hide menuitems
    if(obj = document.getElementById('menuitems_'+id)) {
        obj.style.display = 'none';
    }
}

function _hide_all()
{
    var obj;
    
    for(var i=0; i<_menu_locktree.length; i++) {
        _hide_submenu(_menu_locktree[i],i);
    }
    _menu_locktree = new Array();
    _show_menu_debug();
}

function _show_submenu(id, parent, depth)
{
    var submenu = document.getElementById('menuitems_'+id);
    var parent_menu = document.getElementById('menuitems_'+parent);
    var menuitem = document.getElementById('item_'+id);

	if(submenu) {
        
        //if(0 == parent && menustyle == 0 ) {
            //var itemtop = parent_menu.offsetTop + menuitem.offsetTop + menuitem.offsetHeight;
            //var itemleft = parent_menu.offsetLeft + menuitem.offsetLeft;
        //} else {
            var itemtop = parent_menu.offsetTop + menuitem.offsetTop + 1;
            var itemleft = parent_menu.offsetLeft + menuitem.offsetWidth - 3;
        //}
        
        submenu.style.top = itemtop + 'px';
        submenu.style.left = itemleft + 'px';
        submenu.style.display = '';
    }
    
    menuitem.className = 'fp_menuitem fp_menuitem_hover_'+Math.min(menu_max_class_depth,depth+menu_start_depth);
}

function _show_menu_debug()
{
    if(_menu_debug) {
        var obj = document.getElementById('_menu_debug_div');
        var msg = '';
        
        msg += "_menu_locktree ("+_menu_locktree.length+") = (\n";
        for(var i in _menu_locktree) {
            msg += "\t"+i+" => "+_menu_locktree[i]+"\n";
        }
        msg += ")\n";
        
        obj.innerHTML = '<pre>'+msg+'</pre>';
    }
}

//  debugging
if(_menu_debug) {
    document.write('<div id="_menu_debug_div" style="position: absolute;padding:8px; width: 200px; height:140px; left:10px;top:300px;border:2px solid black; background-color: white; z-index: 99"></div>');
}