here is the code for menu.

Code:
    (document).ready(function(){

    $("#main-nav li a.main-link").hover(function(){
    $("#main-nav li a.main-link").removeClass("active");
    $(this).addClass("active");
    $("#sub-link-bar").animate({
    height: "40px"
    });
    $(".sub-links").hide();
    $(this).siblings(".sub-links").fadeIn();

    });


    $("#main-nav").mouseleave(function(){

    $("#main-nav li a.main-link").removeClass("active");
    $(".sub-links").fadeOut();
    $("#sub-link-bar").animate({
    height: "10px"
    });
    });
    });
I want to add functionality so that

1) sub menu is hidden if mouse is moved down of main menu

2) sub menu is hidden if page is scrolled down

3) keep sub menu open on hover

Please reply. Thanks.