/**
 * @author andreas karl
 */

$(document).ready(function(){
	$('.hideUL, .hideLang').hide();
	
	var menuElement = false;
	var lastOver;
	var maxMenuElementHight = 0;
	var position = 0;
	var outElement = false;
	$("#headNavi").children().mouseover(function(){
		
		if(!position)
			position = $("#headNavi").position();
			
		if($(menuElement).attr('id') != $(this).attr('id')){
			if(menuElement){
				$(menuElement).children('ul').hide();
				maxMenuElementHight = 0;
			}
			menuElement = $(this);
			
			if(maxMenuElementHight < $(menuElement).children('ul').height())
				maxMenuElementHight = $(menuElement).children('ul').height() + 20 +position.top;
			
			$('.hideUL').hide();
			
			setTimeout(function(){
				$('.hideUL').hide();
				$(menuElement).children('ul').slideDown('fast');
			}, 500);
		}
	});
	$('#headNavi').children().mouseout(function(e){
		outElement = $(this);
		if(maxMenuElementHight < e.pageY || e.pageX <= position.left || e.pageX >=( position.left + $("#headNavi").width()-250) || e.pageY <= position.top){
			$(menuElement).children('ul').hide();
			menuElement = false;
		}
		
	});

// CLICK FCT FOR LANGUAGE MENU
	$('.pulldown').click(function (){
		$('.hideLang').slideToggle("slow");
		setTimeout(function(){
			$('.hideLang').slideToggle("slow");
		},8000);
	});

});

