
function get_next_object_by_tag(_s_tag, _objparent)
{
	var arr_children = _objparent.getChildren();
	for(var i = 0; i < arr_children.length; i++)
	{
		if (arr_children[i].get('tag') == _s_tag)
			return arr_children[i];
	}

	//we didnt found any, so we check in our childrens:
	for(var i = 0; i < arr_children.length; i++)
	{
		var obj_tmp = get_next_object_by_tag(_s_tag, arr_children[i]);
		if (obj_tmp != null) return obj_tmp;
	}

	return null;
}

window.addEvent('domready', function()
{
	//we first make sure the #searchcontainer is the same height as the #maincontent:
	if (
		$('maincontent') && 
		$('searchcontainer')
	)
	{
		//we get our sizes:
		var i_search_height = $('searchcontainer').getSize().y.toInt();
		var i_main_height = $('maincontent').getSize().y.toInt();

		//we then verify if the main is bigger than the search:
		if (i_main_height > i_search_height)
		{
			//we adjust the search height:
			$('searchcontainer').setStyle('height', i_main_height - 55);
		}
	}

	//we first make sure the #searchcontainer is the same height as the #maincontent-interior:
	if (
		$('maincontent-interior') && 
		$('searchcontainer')
	)
	{
		//we get our sizes:
		var i_search_height = $('searchcontainer').getSize().y.toInt();
		var i_main_height = $('maincontent-interior').getSize().y.toInt();

		//we then verify if the main is bigger than the search:
		if (i_main_height > i_search_height)
		{
			//we adjust the search height:
			$('searchcontainer').setStyle('height', i_main_height - 55);
		}
	}

	//we then adjust the opacity of our headlines tag(s):
	$$('.headlines').setStyle('opacity', 0.5);

	//we then make our sub header menu work:
	$$('#subtopcontainer .firstmenu li .triggerenter').addEvent('mouseenter', function(_evt)
	{
		//we get our sub menu, if any:
		var obj_menu = get_next_object_by_tag('ul', this.getParent());
		if (obj_menu != null)
		{
			//we set our display at true:
			obj_menu.setStyle('display', 'block');

			//we set our z-index to 2:
			obj_menu.getParent().setStyle('z-index', 3);

			//we add the selected class to our link:
			this.set('class', 'selected');

			//we set its right position:
			var obj_new_pos = this.getParent().getPosition();
			var obj_pos = obj_menu.getPosition();

			var i_window_offset_x = (window.getSize().x - $('maincontainer').getSize().x) / 2;
			obj_menu.getParent().set('styles', {'top': obj_new_pos.y + this.getParent().getSize().y, 'left': obj_new_pos.x + 15});
	
			//we show the menu:
			obj_menu.setStyle('visibility', 'visible');

			//we slide in:
			new Fx.Tween(obj_menu).start('opacity', 0, 1);
		}
	});

	$$('#subtopcontainer .firstmenu .triggerleave').addEvent('mouseleave', function(_evt)
	{
		//we get our sub menu, if any, then fade out:
		var obj_menu = get_next_object_by_tag('ul', this);
		if (obj_menu != null)
		{
			//we remove our class:
			get_next_object_by_tag('a', this).removeClass('selected');

			//we set our z-index to 2:
			obj_menu.getParent().setStyle('z-index', 2);

			//we slide out:
			new Fx.Tween(obj_menu/*, {'onComplete': function(){obj_menu.getParent().setStyles({'left': 0, 'top': 0});}}*/).start('opacity', 1, 0);
		}
	});

});

sfHover = function() { 
	var sfEls = document.getElementsByTagName("LI"); 
		for (var i=0; i<sfEls.length; i++) { 
			sfEls[i].onmouseover=function() { 
			this.className+=" sfhover"; 
		} 
		sfEls[i].onmouseout=function() { 
			this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); 
		} 
	} 
}

if (window.attachEvent)
{
    window.attachEvent("onload", sfHover);
}

