jQuery(document).ready(function() {

	 jQuery('.flapmenu').each(function(i) {
		 var el = jQuery(this);
		 var movedIn = false;
		 
		 // add hover listener
		 el.parent().hover(function() {
			 movedIn = true;
			 setTimeout(function() {
			 	if (movedIn) {
			 		el.fadeIn('fast', function() {
			 			el.css("display", "block");
			 		});
			 	}
			 }, 250);
		 }, function() {
		 	movedIn = false;
			 setTimeout(function() {
			 	if (!movedIn) {
			 		el.fadeOut('fast', function() {
			 			el.css("display", "none");
			 		});
			 	}
			 }, 250);
		 });
		 
		 // re-place the flapmenu
		 var topChange = Math.min(el.height(), 198);
		 el.css('top', -topChange);
		 
		 var liCount = $('.mainnav').children().length;
		 if (i >= liCount/2) {
		 	// place menu on the right side
		 	var widthChange = jQuery('#banner').width() - el.width();
		 	el.css('left', widthChange);
		 }
	 });


	if (jQuery("#overviewnav li") != null) {
		/*
		jQuery("#overviewnav li").hover(
			
			function(){jQuery(this).addClass("hover")},
			function(){jQuery(this).removeClass("hover")}
		);
		*/
			
		jQuery("#overviewnav li").click(
			function() {
				window.location = "http://" + window.location.host + "/" + jQuery(this).find('.title').children('a').attr('href');
				
			}
		);
	}

	jQuery(".news-list-container li").click(
		function() {
			var link = jQuery(this).find('.news-list-headline').children('.link').children('a').attr('href');
			var target = jQuery(this).find('.news-list-headline').children('.link').children('a').attr('target');
			if (target == "_blank") {
				window.open(link, target);
			}
			else {
				window.location = link;
			}
			
		}
	);
});

function menuTest() {
	jQuery("#mainnav li").each(function(i) {
		if (i>1) return false;
		jQuery(this).trigger('mouseover'); 
	});
}

