var close_menu = function(how_fast)
{
	$$('.unter_menu').each(function(e)
	{
		e.set('morph', {duration: how_fast, transition: 'bounce:out'});
		e.morph({'height': '0px;'});
	});
}
var active_menu = function(elem)
{
	var parent = $(elem).getParent('.haupt_menu_punkt');
	if(parent.getElement('.unter_menu'))
	{
		var height = parseInt(parent.getElement('.unter_menu').getSize().y);
		parent.getElement('.unter_menu').set('morph', {duration: 'long', transition: 'bounce:out'});
		parent.getElement('.unter_menu').morph({'height': height+'px;'});
	}
	var color = '#fff';
	if($(elem).getAttribute('class') == 'line cams')
	{
		var color = '#000';
	}
	$(elem).setStyles({
		backgroundPosition: '0px -52px',
		color: color
	});
}
window.addEvent('domready', function()
{
	resizeWindow(900, 600);
	close_menu('short');
	
	if($('that_active'))
	{
		active_menu('that_active');
	}
	$$('.haupt_menu_punkt').each(function(foo)
	{
		if(foo.getElement('.unter_menu'))
		{
			foo.getElement('.unter_menu').setAttribute('self_height', foo.getElement('.unter_menu').getSize().y);
		}
		foo.getElement('.line').addEvents(
		{
			'mouseover' : function()
			{
				if(foo.getElement('.line').getStyle('backgroundPosition') != '0px -52px')
				{
					foo.getElement('.line').setStyle('backgroundPosition', '0 -26px');
				}
			},
			'mouseout' : function()
			{
				if(foo.getElement('.line').getStyle('backgroundPosition') != '0px -52px')
				{
					foo.getElement('.line').setStyle('backgroundPosition', '0 0');
				}
			},
			'click': function()
			{
				$$('.haupt_menu_punkt').getElement('.line').setStyles({
					backgroundPosition: '0 0',
					color: '#000'
				});
				var color = '#fff';
				if(foo.getElement('.line').getAttribute('class') == 'line cams')
				{
					var color = '#000';
				}
				foo.getElement('.line').setStyles({
					backgroundPosition: '0px -52px',
					color: color
				});
				if(foo.getElement('.unter_menu'))
				{
					var unter_menu = foo.getElement('.unter_menu');
				}
				close_menu('long');
				if(foo.getElement('.unter_menu'))
				{
					unter_menu.set('morph', {duration: 'long', transition: 'bounce:out'});
					unter_menu.morph({'height': unter_menu.getAttribute('self_height')});
				}
			}
		});
	});
	$$('img.show_me').each(function(foo)
	{//damit die service bilder im popup aufgehen
		foo.addEvent('click', function()
		{
			window.open(str_replace('?h=90', '', foo.src), 'show', 'width=800, height=620, top=50');
		});
	});
});
var str_replace = function(mysearch, myreplace, mysubject)
{//wie PHP str_replace();
    return mysubject.split(mysearch).join(myreplace);
}