var menu = {
    init: function() {
        var vCurrentDD;
        $('.menuItem').each(function() {
            var vId = $(this).attr('id').substr(4);
            var vDropDown = $('#dropDownMenu' + vId);
            if(vDropDown[0]) {
                $(this).find('.menuItemLink').click(function() {
//                    return false;
                });
            }
            var vTO;
            $(this).mouseover(function() {
                if(vCurrentDD && vCurrentDD != vDropDown)
                    vCurrentDD.hide();
                vCurrentDD = vDropDown;
                if(vTO) {
                    clearTimeout(vTO);
                    vTO = null;
                    return;
                }
                vDropDown.stop();
                vDropDown.css('opacity', null);
                vDropDown.hide();
                vDropDown.fadeIn(300);
            });
            $(this).mouseout(function() {
                clearTimeout(vTO);
                vTO = setTimeout(function() {
                    clearTimeout(vTO);
                    vTO = null;
                    vDropDown.stop();
                    vDropDown.fadeOut(300);
                }, 100);
            });
            /*
            $(this).click(function() {
                if(vDropDown[0])
                    return false;
            });
            */
        });

        var vCurrentDD2;
        $('.dd1Item').each(function() {
            var vId = $(this).attr('id').substr(4);
            var vDropDown = $('#dropDownMenu' + vId);
            var vTO;
            $(this).mouseover(function() {
                clearTimeout(vTO);
                vDropDown.css('margin-left', $(this).width());
                vDropDown.fadeIn(300);
                if(vCurrentDD2 && vCurrentDD2 != vDropDown)
                    vCurrentDD2.hide();
                vCurrentDD2 = vDropDown;
            });
            $(this).mouseout(function() {
                clearTimeout(vTO);
                vTO = setTimeout(function() {
                    vDropDown.fadeOut(300);
                }, 100);
            });
        });
        $('.dropDownItem').mouseover(function() {
            $(this).addClass('hover');
        });
        $('.dropDownItem').mouseout(function() {
            $(this).removeClass('hover');
        });
        $('.dropDownMenu .arrowed').click(function() {
            return false;
        });
    }
};

$(window).ready(function() { menu.init(); });
