var timerObj;
var aktMenue = false;
var aktSubMenue = false;
var collapseMS = 1000; // Menues nach 1 Sekunde schliessen

var hideMenue = function (id) {
    if (aktMenue == false && aktSubMenue == false) jQuery('.snav').hide('slow');
}

var showAkt = function (id) {
    var txt = 'aktMenue=' + aktMenue;
    txt += ' aktSubMenue=' + aktSubMenue;
    txt += ' | ' + Math.random();
    jQuery('#debug').html( txt );
    window.setTimeout('showAkt()',500);
}

var createNavi = function () {
    //window.setTimeout('showAkt()',500);

    jQuery('#mainnavi > A.mnav').each(function (i){
        var pos = jQuery(this).position();
        jQuery('#sub' + this.id).css('left',pos['left']);

        jQuery(this).mouseover(function () {
            var m_id = this.id;
            var sm_id = 'sub' + m_id;
            jQuery('.snav').hide();
            jQuery('#' + sm_id).show();

            aktMenue = m_id;
            timerObj = window.setTimeout('hideMenue()',collapseMS);
        });
        jQuery(this).mouseout(function () {
            aktMenue = false;
            if (timerObj) window.clearTimeout(timerObj);
            timerObj = window.setTimeout('hideMenue()',collapseMS);
        });
    });

    jQuery('.snav').each(function (i){
        jQuery(this).mouseover(function () {
            aktSubMenue = this.id;
            if (timerObj) window.clearTimeout(timerObj);
        });
        jQuery(this).mouseout(function () {
            if (timerObj) window.clearTimeout(timerObj);
            timerObj = window.setTimeout('hideMenue()',collapseMS);
            aktSubMenue = false;
        });
    });
}

jQuery(document).ready(function () {
    createNavi();
});

