/*
 *
 * BuHV Navigationsscript
 * Copyright (c) 2009 graphodata ag
 *
 */

$(document).ready(function(){

	var naviwidth = $('#navibox').width();
	
	var activeparent = $('.navi-1 li.active').parent();
	if (activeparent.html() != null)
	{
		activeparent.css('visibility','visible');
		var pos = 0; var height = 0; var newtop = 0;
		pos = activeparent.parent().position();
		height = activeparent.height();
		if ((pos.top + height) > $('#navibox').height())
		{
			newtop = $('#navibox').height() - height;
			activeparent.css({'top':newtop-7});
		}
		else
		{
			activeparent.css({'top':pos.top});
		}
		activeparent.parent().addClass('activeparent');
	}
	$('.navi-0 li:not(.navi-1 li)').mouseenter( function()
	{
		activeparent.css('visibility','hidden');

	});
	
	$('.navi-0').mouseleave( function()
	{
		activeparent.css('visibility','visible');
	});
	
	

	/* ========== MENÜEBENE 1 ========== */
	$('.navi-0 li:not(.navi-1 li)').mouseenter( function()
	{
		$(this).addClass('hover');
		var pos = 0; var height = 0; var newtop = 0;
		pos = $(this).position();
		height = $('> ul', this).height();
		if ((pos.top + height) > $('#navibox').height())
		{
			newtop = $('#navibox').height() - height;
			$('> ul', this).css({'top':newtop-7});
		}
		else
		{
			$('> ul', this).css({'top':pos.top});
		}
		$('> ul', this).css('visibility','visible');
	});

	$('.navi-0 li').mouseleave( function()
	{
		$('> ul', this).css('visibility','hidden');
		$(this).removeClass('hover');
	});


	/* ========== MENÜEBENE 2 ========== */
	$('.navi-1 li').mouseenter( function()
	{
		$(this).addClass('hover');	
		if ($(this).hasClass('noclick'))
		{
			var pos = 0; var height = 0; var newtop = 0; var parent = 0;
			pos = $(this).position();
			parent = $(this).parent('.navi-1').position();
			height = $('> ul', this).height();
			if ((pos.top + height + parent.top) > $('#navibox').height())
			{
				newtop = $('#navibox').height() - height - parent.top;
				$('> ul', this).css({'top':newtop-7});
			}
			else
			{
				$('> ul', this).css({'top':pos.top});
			}
			$('#navibox').width(naviwidth + naviwidth/2)
		}
		$('> ul', this).css('visibility','visible');
	});

	$('.navi-1 li').mouseleave( function()
	{
		$('> ul', this).css('visibility','hidden');
		$(this).removeClass('hover');
		if ($(this).hasClass('noclick'))
		{
			$('#navibox').width(naviwidth)
		}
	});

});
