var ecoloss_menu_c = function()
{
	this.core_c = new cms_core_c();
	this.timeout_i = 0;
	this.exception_a = [];
	this.child_parent_a = [];
	this.last_parent_i = 0;
	this.last_child_i = 0;
	this.parent_a = [];
	this.div_a = [];
	this.app_id_s = '';
	this.right_i = 0;

	/**/

	this.getParentNameByElement = function(element_o)
	{
		return element_o.id.split('X')[2];
	};

	this.getChildNameByElement = function(element_o)
	{
		return element_o.id.split('X')[3];
	};

	this.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;
	};

	/**/

	this.setDivArray = function()
	{
		var div_a = document.getElementsByTagName('div');

		for (var i_i = 0; i_i < div_a.length; i_i++)
	    {
	    	var id_s = div_a[i_i].getAttribute('id');

	        if (id_s && (id_s.substring(0, this.app_id_s.length) == this.app_id_s))
	        {
	            var part_a = div_a[i_i].getAttribute('id').split('X');

	            if (part_a.length == 2)
	            {
		            var object_a = [];
		            	object_a['id'] = part_a[1];
		            	object_a['div'] = div_a[i_i];

		            this.div_a[this.div_a.length] = object_a;
		        }
	        }
	    }
	};

	this.setParentArray = function()
	{
		var host_o = this;
		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].getAttribute('id') ? element_a[i_i].getAttribute('id').split('X') : false;

	    	if (part_a.length == 4)
	    	{
	    		if (part_a[0] == this.app_id_s)
	    		{
	    			element_a[i_i].menu_parent_i = part_a[2];
	    			element_a[i_i].menu_child_i = part_a[3];
	    			element_a[i_i].onclick = function() { host_o.setChildLink(this); };
	    			element_a[i_i].onmouseover = function() { host_o.setOver(this, this.menu_parent_i, this.menu_child_i); };
	    			element_a[i_i].onmouseout = function() { host_o.setOut(this); };

	    			this.parent_a[this.parent_a.length] = element_a[i_i];
	    		}
	    	}
	    }
	};

	/**/

	this.setClassSwitch = function(element_o, from_name_s, to_name_s)
	{
		var link_a = element_o ? element_o.getElementsByTagName('a') : [];

	    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.
	    }
	};

	this.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 ? [] : this_o.exception_a;
		this_o.child_parent_a = timeout_b ? [] : 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.display = 'none';
	        	this_o.setClassSwitch(parent_o, 'over', 'out');
	        }
	        else this_o.setClassSwitch(parent_o, 'out', 'over');
	    }
	};

	/**/

	this.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.app_id_s + 'X' + child_i);

	        if (child_de)
	        {
		        child_de.style.top = this.core_c.getY(current_de) + this.core_c.getHeight(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.explorer_b ? (parent_i ? 0 : 2) : 0)) + 'px';
		        child_de.style.display = '';
		    }
	    }
	};

	this.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);
	};

	this.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');
	};

	/**/

	this.setAppId = function(id_s)
	{
		this.app_id_s = id_s;
	};

	this.setRight = function(state_i)
	{
		this.right_i = state_i;
	};

	this.setPrepare = function()
	{
		this.setDivArray();
		this.setParentArray();
		this.setCollapse();
	};
};