$(document).ready(function() {
	var pathName = window.location.pathname;
	var search = /(presse)/g;
	var pageIsPress = search.test(pathName);
	if (pageIsPress == false) {
		animateNavigation();
	}	
});

var hidingTimeout;
var widthMenuTextEm = 0;
var hidden = true;


function animateNavigation()
{
		
	// css-hover Überschreiben
	$("div#prim-nav-area").css("top","auto");
	$("div#prim-nav-area").css("left","auto");
	$("div#prim-nav-area").css("width","100%");
	// ie
	$("a#prim-nav-area-ie").css("top","auto");
	$("a#prim-nav-area-ie").css("left","auto");
	$("a#prim-nav-area-ie").css("width","100%");
	

	$("a#menu-button").mouseover(function(event){
  		event.stopPropagation();
		// zeige nur wenn versteckt --> verhindert das bouncing
		if(hidden)
		{
			showNavigation();
		}
		return false;
	});
	
	$("div#prim-nav-area").mouseout(function(event){
		event.stopPropagation();
		window.clearTimeout(hidingTimeout);
		hidingTimeout = window.setTimeout("hideNavigation()", 500);
		return false;
	});
	
	
	$("div#prim-nav-area").mouseover(function(event){
  		event.stopPropagation();
		window.clearTimeout(hidingTimeout);
		return false;
	});
	
	// onresize --> navigation
	$(window).resize(function () 
	{
    	resizeNavigation();
    }); 
		
		
	// breite der navigatiosntexte berechnen
	if(widthMenuTextEm == 0)
	{
		$("ul#prim-nav").children().each(
			function()
			{
				widthMenuTextEm += this.offsetWidth;
			}
		);
		widthMenuTextEm /= 10;
	}
	
	
	// calculate the position of the navigation 
	// according to the menu button
	resizeNavigation();
	
	// hide navigation
	$("div#prim-nav-area").hide();
	
}

function showNavigation()
{
	// pixelgenau positionieren --> benötigt für die verschiebung
	var navigationHeight = $("div#prim-nav-area").css('height');
	if(typeof navigationHeight != "undefined" && emToPx(navigationHeight) != 0)
	{
		$("div#prim-nav-area").css("top", -emToPx($("div#prim-nav-area").css('height')));
	}
	else
	{
		$("div#prim-nav-area").css("top", (-$("div#prim-nav-area").height())+"px");
	}
	
	// animate the navigation
	$("div#prim-nav-area").show().animate({
		  top: 0
			},750,function(){
			
				$(this).animate({
				  top: -10
				},350);	
		
	});
	

	hidden = false;
}


function hideNavigation()
{
	// animate the navigation
	$("div#prim-nav-area").animate({
	  top: -$("div#prim-nav-area")[0].offsetHeight
	  	},600, function(){
		// hide navigation
		$(this).hide();		
	});
	
	hidden = true;
}


function resizeNavigation()
{	

	// hide the navigation
	$("div#prim-nav-area").css("top", -$("div#prim-nav-area")[0].offsetHeight);
	hidden = true;
	
	// new position
	var newPositionEm = getAbsolutePosition($("a#menu-button")[0]).x / 10;
	$("ul#prim-nav").css("padding-left",newPositionEm+"em");
	
	// window size
	var windowWidth;
    //For old IE browsers 
	if(document.all) 
	{ 
		windowWidth  = document.body.clientWidth; 
	} 
	//For DOM1 browsers 
	else if(document.getElementById &&!document.all)
	{ 
		windowWidth = innerWidth; 
	} 
	else if(document.getElementById) 
	{ 
		windowWidth = innerWidth; 
	} 
	//For Opera 
	else if (is.op) 
	{ 
		windowWidth = innerWidth; 
	} 
	//For old Netscape 
	else if (document.layers) 
	{ 
		windowWidth = window.innerWidth; 
	}
	
	// navigation width
	var navigationWidthEm = windowWidth / 10 - newPositionEm - 2;


	// bei kleiner breite abbr&uuml;che erlauben
	if(navigationWidthEm >= 63)
	{ // Zeilenumbruch deaktivieren
		$("ul#prim-nav li li").css("white-space","nowrap");
	}
	else if(navigationWidthEm < 63)
	{ // Zeilenumbruch aktivieren
		$("ul#prim-nav li li").css("white-space","normal");		
	}

	// nicht &uuml;ber einander rutschen
	if(navigationWidthEm < 45)
	{
		navigationWidthEm = 45;
	}
	
	
	// new position
	var distanceEm = (navigationWidthEm - widthMenuTextEm) / 5;

	$("li#prim-nav-2").css("left",distanceEm+"em");
	
	var newDistandEm = distanceEm + distanceEm;
	$("li#prim-nav-3").css("left",newDistandEm+"em");
	
	newDistandEm = newDistandEm + distanceEm;
	$("li#prim-nav-4").css("left",newDistandEm+"em");
	
	newDistandEm = newDistandEm + distanceEm;
	$("li#prim-nav-5").css("left",newDistandEm+"em");

	
}

