var all_layers  = new Array();

function register_switches(layer_id, switch_id_on, switch_id_off)
{
    var layer = get_layer(layer_id);
    var switch_on = document.getElementById(switch_id_on);
    var switch_off = document.getElementById(switch_id_off);
    layer.addSwitches(switch_on, switch_off);
}

function close_layers()
{
    for (var i = 0; i < close_layers.arguments.length; i++)
	{
		for (var j = 0; j < close_layers.arguments[i].length; j++)
		{
			var layer = get_layer(close_layers.arguments[i][j]);
			if (layer.visible)
			{
				layer.hide();
			} // if
    	} // for
	} // for
} // function

function show_layers()
{
    for (var i = 0; i < show_layers.arguments.length; i++)
	{
		var layer = get_layer(show_layers.arguments[i]);
		layer.show();
	} // for
} // function

function toggle_layer()
{
    for (var i = 0; i < toggle_layer.arguments.length; i++)
	{
        var layer = get_layer(toggle_layer.arguments[i]);
        if (layer.visible)
		{
            layer.hide();
        }
		else
		{
            layer.show();
        }
    }
}

function get_layer(id)
{
    if (all_layers[id] != null)
	{
        return all_layers[id];
    }
	else
	{
        var temp = new __layer(id);
        all_layers[id] = temp;
        return temp;
    }
}

function __layer(layer_id)
{
    this.switch_on = new Array();
    this.switch_off = new Array();
    this.visible = true;
    this.id  = layer_id;
    this.getId  = __get_layer_id;
    this.show  = __layer_show;
    this.hide  = __layer_hide;
    this.addSwitches = __add_switches;
}

function __get_layer_id()
{
    return this.id;
}

function __layer_show()
{
    document.getElementById(this.getId()).style.display = 'block';
    this.visible = true;
    if (this.switch_off != null && this.switch_off.length > 0)
	{
        for (var i = 0; i < this.switch_off.length; i++)
		{
            var temp = this.switch_off[i];
            temp.style.display = 'none';
        }
    }
    if (this.switch_on != null && this.switch_on.length > 0)
	{
        for (var i = 0; i < this.switch_on.length; i++)
		{
            var temp = this.switch_on[i];
            temp.style.display = 'inline';
        }
    }
}

function __layer_hide()
{
    document.getElementById(this.getId()).style.display = 'none';
    this.visible = false;
    if (this.switch_off != null && this.switch_off.length > 0)
	{
        for (var i = 0; i < this.switch_off.length; i++)
		{
            var temp = this.switch_off[i];
            temp.style.display = 'inline';
        }
    }
    if (this.switch_on != null && this.switch_on.length > 0)
	{
        for (var i = 0; i < this.switch_on.length; i++)
		{
            var temp = this.switch_on[i];
            temp.style.display = 'none';
        }
    }
}

function __add_switches(switchon, switchoff)
{
    this.switch_on[this.switch_on.length] = switchon;
    this.switch_off[this.switch_off.length] = switchoff;
}