function find_parent_by_class_name(_obj, _s_class)
{
	//we get our children:
	var arr_children = _obj.getChildren();
	for(var i = 0; i < arr_children.length; i++)
	{
		if (arr_children[i].get('class') == _s_class)
			return arr_children[i];
	}

	for(var i = 0; i < arr_children.length; i++)
	{
		var mixed_tmp = find_parent_by_class_name(arr_children[i], _s_class);
		if (mixed_tmp != null)
			return mixed_tmp;
	}

	return null;
}

var topmenu = new Class(
{
	marr_data: Array(),
	mobj_lastopenid: null,
	initialize: function()
	{
		//we set our objects:
		this.set_objects($$('#topmenu .firstlevel .firstcell'));
	},
	set_objects: function(_arr_data)
	{
		var obj_this = this;
		for(var i = 0; i < _arr_data.length; i++)
		{
			//we set an id:
			_arr_data[i].setProperty('id', 'cell_' + Math.floor(Math.random()*10000));

			//we add our mousenter and mouseleave effects:
			_arr_data[i].addEvent('mouseenter', function() { obj_this.effect_mouseenter(this.getProperty('id')); });
			_arr_data[i].addEvent('mouseleave', function() { obj_this.effect_mouseleave(this.getProperty('id')); });

			//we create our effect:
			var obj = find_parent_by_class_name(_arr_data[i], 'secondmenu');
			this.marr_data[i] = {'object': _arr_data[i], 'effect': new Fx.Tween(obj, {'link': 'chain'})};
		}
	},
	effect_mouseenter: function(_i_id)
	{
		//we begin by closing our last open:
		if (this.mobj_lastopenid)
		{
			var obj = this.find_effect_by_objectid(this.mobj_lastopenid);
			obj.start('opacity', 1, 0);
		}

		var obj = this.find_effect_by_objectid(_i_id);
		obj.start('opacity', 0, 1);
		this.mobj_lastopenid = _i_id;
	},
	effect_mouseleave: function(_i_id)
	{
		var obj = this.find_effect_by_objectid(_i_id);
		obj.start('opacity', 1, 0);
		this.mobj_lastopenid = null;
	},
	find_effect_by_objectid: function(_i_id)
	{
		for(var i = 0; i < this.marr_data.length; i++)
		{
			if (this.marr_data[i].object.getProperty('id') == _i_id)
				return this.marr_data[i].effect;
		}

		return null;
	}
});

window.addEvent('domready', function() 
{
	new topmenu();
	//we add our event:
	/*$$('#topmenu .firstlevel .firstcell').addEvent('mouseenter', function()
	{
		//we get its ul child:
		var obj = find_parent_by_class_name(this, 'secondmenu');
		new Fx.Tween(obj, {'link': 'ignore'}).start('opacity', 0, 1);
	});

	$$('#topmenu .firstlevel .firstcell').addEvent('mouseleave', function()
	{
		//we get its ul child:
		var obj = find_parent_by_class_name(this, 'secondmenu');
		new Fx.Tween(obj, {'link': 'ignore'}).start('opacity', 1, 0);
	});*/
});
