
function initMenus() 
{
	$('ul.menu ul').hide();
	
	$.each($('ul.menu'), function()
	{
		var cookie = $.cookie(this.id);
		var subcookie = $.cookie('subitem');
		
		if(cookie === null || String(cookie).length < 1) 
		{
			$('#' + this.id + '.expandfirst ul:first').show();
		}
		else 
		{			
			$('#' + this.id + ' #' + cookie).next().show();
			
			if($('#' + this.id + ' #' + cookie).next().is('ul'))
			{
				$('#' + this.id + ' #' + cookie).addClass('active');
			}
			else
			{
				$('#' + this.id + ' #' + cookie).addClass('active2');
			}
		}
		
		if (subcookie != null)
		{
			$('#'+ subcookie).addClass('subactiv');
		}
	});

/*	
	$('#aLogo').click( function () )
	{
		var delParent = $('ul.menu').id;
		$.cookie(delParent, null);
		return false;
	};)
*/		
	
	$('.subitem').click(
			function () {
				$.cookie('subitem', this.id, { path: '/' });
			}
		);
	
	$('ul.menu li a').click(
		function() {

			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			var cookie = $.cookie(parent);
			
			if($('#' + parent).hasClass('noaccordion')) {
				if((String(parent).length > 0) && (String(this.className).length > 0)) {
					if($(this).next().is(':visible')) {
						$.cookie(parent, null, { path: '/' });
					}
					else {
						$.cookie(parent, this.id, { path: '/' });
					}
					$(this).next().slideToggle('normal');
				}				
			}
			
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					//$('#' + parent + ' ul:visible').slideUp('normal');
					$('#' + parent + ' ul:visible').hide();
					
				}
				return false;
			}
			
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) 
			{
				//$('#' + parent + ' ul:visible').slideUp('normal');
				if ($(' #' + cookie).next().is('ul'))
				{	
					$(' #' + cookie).removeClass('active');
				}
				else
				{
					$(' #' + cookie).removeClass('active2');
				}
				$('#' + parent + ' ul:visible').prev().removeClass('active2');
				$('#' + parent + ' ul:visible').hide();
				
				if((String(parent).length > 0) && (String(this.id).length > 0)) {
					$.cookie(parent, this.id , { path: '/' });
				}
				//checkElement.slideDown('normal');
				checkElement.show();
				//$(this).css({'background-color' : '#91ba15', 'color': '#fff' , 'background-image' : 'url(\'../../images/navArrowActive.png\')', 'background-repeat' : 'no-repeat', 'background-position' : '10px center'});
				$(this).addClass('active');
				//alert('da');
				// hier muss das oeffnen des ersten submenu-items eingebaut werden
				
				
				return false;
			}
			else
			{
				if((String(parent).length > 0) && (String(this.id).length > 0)) {
					$.cookie(parent, this.id, { path: '/' });
					//alert('ja');
				}
				//alert('ja2');
				//$(this).addClass('active');
			}
		}
	);
	

	
}


