var navigation = {
        effect : 'blind',
        effectConfig : {},
        inTransition : false,
        closing : false,
        
        bind : function() {
                $('#Menu li.first-level').mouseover(function(){
                        var secondLevel = $(this).find('ul.second-level');
                        if (!secondLevel.is(':visible') && !navigation.inTransition) {
                                //hide all other submenus
                                
                                if (!navigation.closing) {
                                        $('#Menu ul.second-level').each(function(){
                                                if ($(this).is(':visible') && !$(this).hasClass('active')) {
                                                        navigation.closing = true;
                                                        $(this).hide(navigation.effect, navigation.effectConfig, function(){
                                                                navigation.closing = false;
                                                        });
                                                }
                                        });
                                }
                                
                                //only run if there are children
                                if (secondLevel.length) {
                                        navigation.inTransition = true;
                                        secondLevel.show(navigation.effect, navigation.effectConfig, function(){
                                                navigation.inTransition = false;
                                        });
                                }
                        }
                });
                
                this.bindSecondLevel();
                
                //open first menu item if on homepage
                if (window.location.pathname == '/' || window.location.pathname == '/home/') {
                        $($('#Menu li.first-level')[0]).trigger('mouseover');
                }
        },
        
        bindSecondLevel : function() {
                $('#Menu li.second-level').mouseover(function(){
                        
                        var thirdLevel = $(this).find('ul.third-level');
                        if (!thirdLevel.is(':visible') && !navigation.inTransition) {
                            
                                
                                //hide all other submenus
                                if (!navigation.closing) {
                                        $('#Menu ul.third-level').each(function(){
                                                
                                                if ($(this).is(':visible') && !$(this).hasClass('active')) {
                                                        navigation.closing = true;
                                                        $(this).hide(navigation.effect, navigation.effectConfig, function(){
                                                                navigation.closing = false;
                                                        });
                                                }
                                        });
                                }
                                
                                //only run if there are children
                                if (thirdLevel.length) {
                                        navigation.inTransition = true;
                                        thirdLevel.show(navigation.effect, navigation.effectConfig, function(){
                                                
                                                navigation.inTransition = false;
                                        });
                                }
                        }
                });
        }
};

