var obj = null;
var sobj = null

function checkHover() {
	if (obj) obj.find('ul.submenu1').fadeOut('fast', function() {
		$('#navigation').css("zIndex", "1");
		$('#navplaceholder').css("zIndex", "1");
	});
} 
function checkHover2() {
	if (sobj) sobj.find('ul.submenu2').fadeOut('fast');	
} 
	
 
$(document).ready(function() {
	/*
		* FIX THE WIDTH OF THE LAST MENU ITEM
		* ADD HOVER FUNCTIONS
	*/
	w1 = $('#navigation').width();
	if($.browser.msie) {
		if(window.location.href.toLowerCase().indexOf("/nl/") > -1) w1 += 15;
		else if(window.location.href.toLowerCase().indexOf("/fr/") > -1) w1 += 32;
		else if(window.location.href.toLowerCase().indexOf("/en/") > -1) w1 += 30;
		w1 += 0; // 36!!
	}
	else w1 += 68;
	w2 = 0;
	
	$('#navigation > li').each( function() {
		w2 += $(this).hasClass("seperator") ? 2 : $(this).width()-2;	
		if($.browser.msie && $(this).html().toLowerCase().indexOf('</ul>') > -1) $(this).css("margin-right", "-5px");
	});
	$('.mostright > a, .mostrightcurrent > a').each( function() {
		$(this).css("padding-left", parseInt($(this).css("padding-left").replace("px", "")) + (parseInt((w1-w2)/2)) + "px");
		$(this).css("padding-right", parseInt($(this).css("padding-right").replace("px", "")) + (w1-w2)-parseInt((w1-w2)/2) + "px");
	});
	
	$('#navigation > li').hover(function() {
		if (obj) {
			obj.find('ul').fadeOut('slow');
			obj = null;
		}
		$(this).find('ul.submenu1').each(function() {
			$('#navigation').css("zIndex", "50");
			$('#navplaceholder').css("zIndex", "45");
			setTimeout("checkHover()", 5000);
			$(this).fadeIn('fast');
		});
		
		$(this).find('ul.submenu1 > li').hover( function() {
			$(this).find('ul.submenu2').each(function() {
				$('#navigation').css("zIndex", "50");
				$('#navplaceholder').css("zIndex", "45");
				setTimeout("checkHover2()", 5000);
				$(this).fadeIn('fast');
			});
		}, function() {
			sobj = $(this);
			obj = null;
			setTimeout("checkHover2()",200);
		});
		
	}, function() {
		obj = $(this);
		setTimeout("checkHover()",200);
	});
});
