/*
 * ZWPLayerMenu
 *
 * Javascript fro Layered Menus.
 *
 * Copyright (C) 2007 Fairfax eCommerce Pty Ltd. All rights reserved.
 *
 */

timeout_length = 1000;	// time in ms; not significant if useTimeouts = 0;
var timeout_flag;

function zwp_layer_menu_init(id)
{
    var e = xGetElementById(id);
    var p =e.parentNode;
    e.style.left = p.offsetWidth+'px';
}


function zwp_layer_menu_is_ancestor(anc, child)
{
    if (child == null || anc == null)
        return false;
        
    var x = child;
    while (zwp_layer_menus[x].parent != '')
    {
        if (zwp_layer_menus[x].parent == anc)
            return true;
        x = zwp_layer_menus[x].parent;
    }
    return false;
}

function zwp_layer_menu_show(id)
{
    zwp_layer_menu_cancel_timer();
    
    for (x in zwp_layer_menus)
    {
        if (zwp_layer_menus[x].parent == "")
            continue;  // Top level menus are not affected.
            
        if (zwp_layer_menu_is_ancestor(x, id) || zwp_layer_menu_is_ancestor(id, x))
            continue; // Ancestors and decendants are not changed.

        var e = xGetElementById(x);
            
        if (x == id)
           e.style.visibility = 'visible';
        else
           e.style.visibility = 'hidden';
    }
}

function zwp_layer_menu_closeall()
{
    for (x in zwp_layer_menus)
    {
        if (zwp_layer_menus[x].parent == '')
            continue;  // Top level menus are not affected.

        var e = xGetElementById(x);
        e.style.visibility = 'hidden';
    }
}

function zwp_layer_menu_start_timer()
{
    clearTimeout(timeout_flag);
    timeout_flag = setTimeout('zwp_layer_menu_closeall()', timeout_length);
}

function zwp_layer_menu_cancel_timer()
{
    clearTimeout(timeout_flag);
}

