window.addEvent('domready', function(){
	new inform_menu($('mainmenu'));
	 
	
});

var inform_menu = new Class(
{
	
	marr_data: Array(),
	initialize: function(_obj_menu)
	{
		var arr_children = _obj_menu.getChildren();

		var obj_this = this;
		for(var i = 0; i < arr_children.length; i++)
		{
			arr_children[i].addEvent('mouseenter', function(_evt){_evt = new Event(_evt).stop(); obj_this.mouseenter(this);});
			arr_children[i].addEvent('mouseleave', function(_evt){_evt = new Event(_evt).stop(); obj_this.mouseleave(this);});

			//we then find the ul element of our element:
			var obj_ul = this.find_children_el(arr_children[i], 'ul');
			
			this.marr_data[i] = null;
			if (obj_ul != null)
			{
				//we set the position of our el:
				var obj_new_pos = arr_children[i].getPosition();
				var obj_pos = obj_ul.getPosition();

				var i_window_offset_x = (window.getSize().x - $('rightcolumn').getSize().x) / 2;
				obj_ul.set('styles', {'top': obj_new_pos.y + 10, 'left': obj_new_pos.x - i_window_offset_x - 150 });

				//we stock our effect:
				this.marr_data[i] = {'objeffect': new Fx.Tween(obj_ul), 'objel': arr_children[i]};
			}
		}
		// Sorts out a sizing issue with the text container
		var obj_rightcolumn = $('rightcolumn');
		if (obj_rightcolumn.getSize().y < 500)
		{
			obj_rightcolumn.set('styles', {'height':500});
		}
		
	},
	mouseenter: function(_obj_el)
	{
		var i_index = this.get_el_index(_obj_el);
		if (i_index == -1)
			return;
		this.marr_data[i_index].objeffect.start('opacity', 0, 1);
	},
	mouseleave: function(_obj_el)
	{
		var i_index = this.get_el_index(_obj_el);
		if (i_index == -1)
			return;

		this.marr_data[i_index].objeffect.start('opacity', 1, 0);
	},
	get_el_index: function(_obj_el)
	{
		for(var i = 0; i < this.marr_data.length; i++)
		{
			if (
				(this.marr_data[i] != null) && 
				(this.marr_data[i].objel == _obj_el)
			)
				return i;
		}

		return -1;
	},
	find_children_el: function(_obj, _s_type)
	{
		//we get our children:
		var arr_data = _obj.getChildren();
		for(var i = 0; i < arr_data.length; i++)
		{
			if (arr_data[i].get('tag') == _s_type)
				return arr_data[i];
		}

		return null;
	}
});

