$('document').ready( function() {
    
    //****************************************
    //
    //  jQuery.dropdownPlain.js - Aspect Software
    //
    //  Custom global navigation for Genuity.com
    //  
    //****************************************
    
    $('.dropdown li').each( function() {
        var max_width = 0;
        var padding = 0;
        
        $(this).find('ul li').each( function() {
            
            //*****
            //
            //  Find the widest anchor in the 
            //  second level navigation and set
            //  each anchor to that width. Furthermore, 
            //  set each anchors respec tive parent
            //  list equal to that width plus the 
            //  left and right padding.
            //
            //*****
            
            var $curr_a = $(this).find('a');
            padding = parseInt($curr_a.css("padding-left")) + parseInt($curr_a.css("padding-left"));       
        
            $curr_a.parent().parent().css({'visibility':'hidden','display':'block'});
            var curr_width = $curr_a.outerWidth();
            $curr_a.parent().parent().css({'visibility':'visible','display':'none'});

            if (curr_width > max_width)
                max_width = curr_width;
        });
        
        $(this).find('ul').css('width', (parseInt(max_width) + padding));
        
        $(this).find('ul li a').each( function() {
            $(this).css('width',max_width);
        });
    });
    
    //*****
    //
    //  Utilize the hoverIntent plugin to 
    //  wire up the slideUp and slideDown 
    //  animations. Set the timeout to the 
    //  delay length before an animation occurs.
    //
    //*****
    
    var hoverConfig = {    
        over: slideMenuDown, 
        timeout: 150, 
        out: slideMenuUp 
    };

    $("ul.dropdown li").hover( slideMenuDown, slideMenuUp );

    function slideMenuDown() { 
        $('ul', this).slideDown(200); 
    }
    
	function slideMenuUp() { 
	    $('ul', this).slideUp(200);
	}        
	
	$("#mainNav ul").hover(
        function () {
            $(this).parent().find('a').addClass("selected");
        },
        function () {
            $(this).parent().find('a').removeClass("selected");
        }
    );
    
    $("#rightLinks ul").hover(
        function () {
            $(this).parent().find('a').addClass("selected");
        },
        function () {
            $(this).parent().find('a').removeClass("selected");
        }
    );

	// Accomadating stay updated form
	$("#rightLinks").hover(
        function () {
			$("#rightLinks").css("position","relative");
			$("#rightLinks").css("z-index","52");
        },
        function () {
			$("#rightLinks").removeAttr("style");
        }
    );
});
