/* ------------------------------------------------------------------------------------------------ */
function horizontalAccordionInit()
{
	if($('header'))
	{
		var horizontalAccordion = new accordion('header', {
			defaultSize : {
				width: 798
			},
			direction : 'horizontal'
		});
		if($$('#header .accordion_toggle')[0])
		{
			horizontalAccordion.activate($$('#header .accordion_toggle')[0]);
		}
	}
}

function verticalAccordionInit()
{
	if($('verticalAccordion'))
	{
		var verticalAccordion = new accordion('verticalAccordion', {
			classNames : {
				toggle : 'vertical_accordion_toggle',
				toggleActive : 'vertical_accordion_toggle_active',
				content : 'vertical_accordion_content'
			}
		});
	//	verticalAccordion.activate($$('#verticalAccordion .vertical_accordion_toggle')[0]);
	}
}

function createTooltips()
{
	$$('img[class="tooltips"]').each(function(element)
	{
		if($(element.id+'_data'))
		{
			new Tip(element, $(element.id+'_data').innerHTML, { delay: 0 });
		}
	});
}

function showSubNav(topnav)
{
	hideAllSubNav();

	if($('subnav_'+topnav))
	{
		$('subnav_'+topnav).style.left = ($(topnav).positionedOffset().left + 38) + 'px';
		new Effect.SlideDown('subnav_'+topnav, { duration:0.2, queue:{ scope:'menuScope', limit: 1 } });
	}
}

function hideSubNav(e, element, subnavid)
{
	var ziel=e.relatedTarget?e.relatedTarget:e.toElement;
	var kinder=element.getElementsByTagName('*');
	for(var i=0;i<kinder.length;i++) { if(kinder[i]==ziel||element==ziel) { return; } }
	$(subnavid).style.display = 'none';
}

function hideAllSubNav()
{
	var queue = Effect.Queues.get('menuScope');
	queue.each(function(effect) { effect.cancel(); });

	$$('div[class="SubNavigation"]').each(
		function(el) {
			el.style.display = 'none';
		}
	);
}

var activeTopnav;
var activeSubnav;
function hoverOn(el)
{
	el.src = el.src.replace(/_disabled/, '_act');
}
function hoverOff(el)
{
	if(el == activeTopnav || el == activeSubnav)
	{
	}
	else
	{
		el.src = el.src.replace(/_act/, '_disabled');
	}
}
function topnavAct(link)
{
	$$('a[href="'+link+'"]').each(
		function(el) {
			if(el.firstChild)
			{
				if(el.firstChild.src)
				{
					el.firstChild.src = el.firstChild.src.replace(/_disabled/, '_act');
					activeTopnav = el.firstChild;
				}
			}
		}
	);
}
function subnavAct(link)
{
	$$('a[href="'+link+'"]').each(
		function(el) {
			if(el.firstChild)
			{
				if(el.firstChild.src)
				{
					el.firstChild.src = el.firstChild.src.replace(/_disabled/, '_act');
					activeSubnav = el.firstChild;
				}
			}
		}
	);
}

Position.GetWindowSize = function(w)
{
	var width, height;
	w = w ? w : window;
	this.width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
	this.height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
	
	return this;
}

function makeMyShadow()
{
	//console.log('window:'+Position.GetWindowSize().height + '; content:'+$('mainContent').getDimensions().height);
	if($('fixHeight'))
	{
		$('fixHeight').style.height = 'auto';
		if(Position.GetWindowSize().height > $('mainContent').getDimensions().height)
		{
			$('fixHeight').style.height = (Position.GetWindowSize().height - $('mainContent').getDimensions().height) + 'px';
		}
		//console.log('fixHeight:' + $('fixHeight').getDimensions().height);
	
		$('shadowLeft').style.height = $('mainContent').getDimensions().height + 'px';
		$('shadowRight').style.height = $('mainContent').getDimensions().height + 'px';
	}
}


var cur_bild = 1;
function galerie(id)
{
	if(cur_bild != id)
	{
		if($('bild_'+id))
		{
			$('bild_'+id).style.display = 'block';
			$('bild_'+cur_bild).style.display = 'none';
	
			$('bildnav_'+id).style.fontWeight = 'bold';
			$('bildnav_'+cur_bild).style.fontWeight = 'normal';
	
			cur_bild = id;
		}
	}
}

/* ------------------------------------------------------------------------------------------------ */
// INITs
Event.observe(window, 'load', makeMyShadow, false);
Event.observe(window, 'load', createTooltips, false);
Event.observe(window, 'load', horizontalAccordionInit, false);
Event.observe(window, 'load', verticalAccordionInit, false);
