var to_hide_interval = 300;
var to_hide_timer2;



$(document).ready(function() {
    menu_item = $('#companyMenu > li');
    child_menu = $('#companyMenu .popup2');

    menu_item.hover(function(e) {mi_over(e, this)}, function(e) {mi_out(e, this)});
    child_menu.hover(function(e) {cm_over(e, this)}, function(e) {cm_out(e, this)});
    
    $('#companyMenu > li > a, #companyMenu > li > span').hover(function(e){
    		var id = $(this).parent().attr('id');
    		if ($('#'+id+'_popup:visible').length>0) {
    				clearTimeout(to_hide_timer2);
    			}
    		},function(e){});
    
    
});


function mi_over(ev, el) {
	var id = $(el).attr('id');
	var id2 = '#'+id+'_popup';
	if ($(id2).length>0) {
		clearTimeout(to_hide_timer2);
	    child_menu.hide();
	    $(id2).show();
	}
}


function mi_out(ev, el) {
	var id = $(el).attr('id');
	var id2 = '#'+id+'_popup';
    to_hide_timer2 = setTimeout(function() {
    	$(id2).hide();}, to_hide_interval
    );
}


function cm_over(ev, el) {
    clearTimeout(to_hide_timer2);
}


function cm_out(ev, el) {
    to_hide_timer2 = setTimeout(function() {
        $(el).hide();}, to_hide_interval
    );
}


