	var maxHeight = 200;

jQuery(function($) { 
/*
	var timeoutArr = [];
	
	var subNavs = $('.subnav').each(function(){
		//timeoutArr.push($(this));
		
	});
*/
    $(".subnav-menus > li").mouseenter(function() {
    	if (typeof(this.timeout) !== undefined) clearTimeout(this.timeout);
    });

    $(".subnav-menus > li").click(function() {
    
    	if (typeof(this.timeout) !== undefined) clearTimeout(this.timeout);
    
        var $container = $(this),
             $wrapper = $container.find("div"),
             $list = $container.find("ul"),
             $anchor = $container.find("a"),
             height = $list.height() * 1,       // make sure there is enough room at the bottom
             multiplier = height / maxHeight;     // needs to move faster if list is taller
        
        // need to save height here so it can revert on mouseout            
        $container.data("origHeight", $container.height()+1);
        
        // so it can retain it's rollover color all the while the dropdown is open
        $anchor.addClass("hover");
        
        // make sure dropdown appears directly below parent list item    
        $list
            .slideDown("fast");
        
        // don't do any animation if list shorter than max
        if (multiplier > 1) {
            $wrapper
                .css({
                    height: maxHeight,
                    overflow: "hidden"
                })
                .mousemove(function(e) {
                    var offset = $wrapper.offset();
                    var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
                    if (relativeY > $container.data("origHeight")) {
                        $list.css("top", -relativeY + $container.data("origHeight"));
                    };
                });
        }
        
    });
    
    $(".subnav-menus > li").mouseleave(function() {
    
        var $el = $(this);
        
        // put things back to normal
        this.timeout = setTimeout(function() { 
		$el
		    //.height($(this).data("origHeight")-1)
		    .find("ul")
		    .css({ top: 0 })
		    .slideUp("fast", function(){
		    	$el.find("a")
		    	.removeClass("hover");
		    });
		    
	}, 500);
    
    });
    
    
});




