var submenuTimer;


// bind click event to menu items
$(".menuitem").live('mouseover', function () {
	// show or hide the underlying submenu if available, otherwise follow the link	 
	
	// stop the submenu-closing-counter (if available)
	clearTimeout(submenuTimer);
	
	// hide all submenu's and deactivate menu's 
	$('.submenu').hide();
	$('.menuitem').removeClass('menuitem_active');
		
	// traverse up to the LI (this = an A right now)
	 var targetSubMenu = $(this).parent().find('.submenu').first();	 
	 if(targetSubMenu.length > 0)
	 {
		targetSubMenu.show();
		$(this).addClass('menuitem_active');		
	 }
	 else
	 {
		// TODO: do something
		alert("geen submenu")
	 }
});

$(".menuitem").live('mouseout', function () {
	// start the submenu-closing-counter. it wil be stopped if a mouseover is on the submenu is triggered
	// otherwise the submenu will be closed
	submenuTimer=setTimeout("$('.submenu').hide()",500);
});


$(".submenu").live('mouseover', function () {
	// stop the submenu-closing-counter (if available)
	clearTimeout(submenuTimer);
});

$(".submenu").live('mouseout', function () {
	// start the submenu-closing-counter. it wil be stopped if a mouseover is on the submenu is triggered
	// otherwise the submenu will be closed
	submenuTimer=setTimeout("$('.submenu').hide()",500);
});


// add right border to submenu's
// viewed from an submenu-item: if there is a next item and the current item is not nr 4,8,12, etc, then show a border 
 $(document).ready(function() {
	$('.submenu').each(function() {
		$(this).find('li').each(function(index){		
			if((index+1) % 4 != 0)
			{
				$(this).css('border-right','2px solid #76A738');
			}			
		});
		$(this).find('li').last().css('border-right','0px solid #76A738');
	});
});


