Timeouts !
var hideTimer;
$('.first').mouseenter(function(){
$('.second').show();
});
$('.first').mouseleave(function(){
hideTimer = setTimeout(function() {
$('.second').hide();
}, 500);
});
$('.second').mouseenter(function(){
clearTimeout(hideTimer);
$('.first').unbind('mouseleave');
});
$('.second').mouseleave(function(){
$('.first').bind('mouseleave');
$('.second').hide();
});
Tweak it to your needs as I'm not sure if I'm following your logic corectly. :P