var maxHeight = 250;


  jQuery(function($){

 

    $(".sub li").hover(function() {
    
         var $container = jQuery(this),
			 $list = $container.find("ul"),
             $anchor = $container.find("a"),
             height = $list.height() * 1.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());
		
		
        
        // 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
           .show()
           
        
        // don't do any animation if list shorter than max
        if (multiplier > 1) {
            $container
                .css('background-color', '#000000')
				.css({
					height: maxHeight,
                    overflow: "hidden"
                })
                .mousemove(function(e) {
                    var offset = $container.offset();
                    var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
                    if (relativeY > $container.data("origHeight")) {
                        $list.css("top", -relativeY + $container.data("origHeight"));
                    };
                });
        }
        
    }, function() {
    
        var $el = jQuery(this),
        $elist = $el.find("ul");
        // put things back to normal
        $el
		.css('background', 'none')
		.removeClass("hover")
        .height(jQuery(this).data("origHeight"));
				//.css('visibility', 'hidden')	
            
			$elist
            .css({ top: 0})
			.hide()
            .end()
            .find("a")
            .removeClass("hover");
    });
    
   
  $("ul.dropdown li").hover(function(){
    
        jQuery(this).addClass("hover");
        jQuery('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        jQuery(this).removeClass("hover");
        jQuery('ul:first',this).css('visibility', 'hidden');
    
    });
  
    $("ul.sub3").hover(function(){
    
        jQuery(this).addClass("hover");
        jQuery('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        jQuery(this).removeClass("hover");
        jQuery('ul:first',this).css('visibility', 'visible');
    
    });
   
    
    
});



