var cms_application_menu_c = function()
{
	this.core_c = new cms_core_c();

	this.timeout_i = 0;

	this.exception_a = new Array();
	this.child_parent_a = new Array();

	this.last_parent_i = 0;
	this.last_child_i = 0;

	this.right_i = 0;

	this.structure_prefix_s = 'structure_';
	this.structure_suffix_s = '_div';

	this.parent_a = new Array();
	this.div_a = new Array();

	this.setDivArray();
	this.setParentArray();
};

/**/

cms_application_menu_c.prototype.setRight = function(state_i)
{
	this.right_i = state_i;
};

/**/

cms_application_menu_c.prototype.getParentNameByElement = function(element_o)
{
	var part_a = element_o.id.split('_');

	return part_a[1];
};

cms_application_menu_c.prototype.getChildNameByElement = function(element_o)
{
	var part_a = element_o.id.split('_');

	return part_a[2];
};

cms_application_menu_c.prototype.getElementByChildName = function(child_i)
{
	for (var i_i = 0; i_i < this.parent_a.length; i_i++)
    {
    	if (this.getChildNameByElement(this.parent_a[i_i]) == child_i)
    	{
    		return this.parent_a[i_i];
    	}
    }

    return false;
};

/**/

cms_application_menu_c.prototype.setDivArray = function()
{
	var div_a = document.getElementsByTagName('div');

	for (var i_i = 0; i_i < div_a.length; i_i++)
    {
        if (div_a[i_i].id.substring(0, this.structure_prefix_s.length) == this.structure_prefix_s)
        {
            var part_a = div_a[i_i].id.split('_');

            var object_a = new Array();
            	object_a['id'] = part_a[1];
            	object_a['div'] = div_a[i_i];

            this.div_a[this.div_a.length] = object_a;
        }
    }
};

cms_application_menu_c.prototype.setParentArray = function()
{
	var element_a = this.core_c.explorer_b ? document.all : document.getElementsByTagName('*');

	for (var i_i = 0; i_i < element_a.length; i_i++)
    {
    	var part_a = element_a[i_i].id ? element_a[i_i].id.split('_') : false;

    	if (part_a.length == 4)
    	{
    		if ((part_a[0] == 'structure') && (part_a[3] == 'x') && part_a[2])
    		{
    			this.parent_a[this.parent_a.length] = element_a[i_i];
    		}
    	}
    }
};

/**/

cms_application_menu_c.prototype.setClassSwitch = function(element_o, from_name_s, to_name_s)
{
	var link_a = element_o ? element_o.getElementsByTagName('a') : new Array();

    if (link_a[0])
    {
    	link_a[0].className = link_a[0].className.replace(from_name_s, to_name_s);
    	element_o.className = element_o.className.replace(from_name_s, to_name_s); // If there's no link, it's a spacer.
    }
};

cms_application_menu_c.prototype.setCollapse = function(this_o, timeout_b)
{
	var this_o = this_o ? this_o : this;

	window.clearInterval(this_o.timeout_i);

	this_o.exception_a = timeout_b ? new Array() : this_o.exception_a;
	this_o.child_parent_a = timeout_b ? new Array() : this_o.child_parent_a;

    this_o.last_parent_i = timeout_b ? 0 : this_o.last_parent_i;
    this_o.last_child_i = timeout_b ? 0 : this_o.last_child_i;

    for (var i_i = 0; i_i < this_o.div_a.length; i_i++)
    {
    	var id_i = this_o.div_a[i_i]['id'];
    	var div_o = this_o.div_a[i_i]['div'];

    	var parent_o = this_o.getElementByChildName(id_i);

    	if (!this_o.exception_a[id_i])
        {
        	div_o.style.visibility = 'hidden';

        	this_o.setClassSwitch(parent_o, 'over', 'out');
        }
        else
        {
        	this_o.setClassSwitch(parent_o, 'out', 'over');
        }
    }
};

/**/

cms_application_menu_c.prototype.setOver = function(current_de, parent_i, child_i)
{
	window.clearInterval(this.timeout_i);

	this.setClassSwitch(current_de, 'out', 'over');

    if (this.last_child_i != child_i)
    {
    	this.exception_a[this.last_child_i] = null;
    }

	if (this.last_parent_i != this.child_parent_a[parent_i])
	{
    	this.exception_a[this.last_parent_i] = null;
   	}

   	this.child_parent_a[child_i] = parent_i;

   	this.exception_a[child_i] = 1;
   	this.exception_a[parent_i] = 1;

   	this.last_child_i = child_i;
   	this.last_parent_i = parent_i;

    this.setCollapse();

    if (child_i)
    {
        var child_de = document.getElementById(this.structure_prefix_s + child_i + this.structure_suffix_s);

        child_de.style.top = this.core_c.getY(current_de) + 'px';
        child_de.style.left = this.right_i ? ((this.core_c.getX(current_de) - child_de.offsetWidth) - (this.core_c.explorer_b ? (parent_i ? 0 : 2) : 0)) + 'px' : (this.core_c.getX(current_de) + this.core_c.getWidth(current_de) + (this.core_c.explorer_b ? (parent_i ? 0 : 2) : 0)) + 'px';

        child_de.style.visibility = 'visible';
    }
};

cms_application_menu_c.prototype.setOut = function(current_de)
{
    window.clearInterval(this.timeout_i);

    this.setClassSwitch(current_de, 'over', 'out');

    this.timeout_i = window.setInterval(this.setCollapse, 400, this, 1);
};

cms_application_menu_c.prototype.setChildLink = function(element_o)
{
	var link_a = element_o ? element_o.getElementsByTagName('a') : [];

    if (link_a[0])
    	document.location.href = link_a[0].getAttribute('href');
};