window.addEvent( 'domready', function( ) {
	

    var allLis = $( 'menu' ).getChildren( );

    // Loops thorough them and add mouseover and mouseout functions
    allLis.each( function( li ) {

        li.addEvent( 'mouseover', function( ) {

            // Give it the class "over"
            this.addClass( 'over' );
            
            if ( window.ie6 )
            {

                $$( 'select' ).each( function( select ) {

                    select.setStyle( 'visibility', 'hidden' );

                });

            }
            
        } );
        
        li.addEvent( 'mouseout', function( ) {

            // Remove the over class when the mouse leaves the menu item
            this.removeClass( 'over' );

            if ( window.ie6 )
            {

                $$( 'select' ).each( function( select ) {

                    select.setStyle( 'visibility', 'visible' );

                });

            }

        });
        
        var left = li.getElement( '.left_drop_down' );
        
        if ( $defined( left ) )
        {

	        // Get the right side drop down menu
	        var right = li.getElement( '.right_drop_down' );
	
	        // Does the right side menu exist?
	        if ( $defined( right ) )
	        {
	        	
	        	// Both are defined, we need to make sure they are the same
	        	// height and positioned correctly.
	        	
	        	// Make them visible and positioned off the screen
	        	left.setStyles( { 
	        		'display': 'block',
	        		'left': '-5000px'	        		
	        	} );
	        	right.setStyles( { 
	        		'display': 'block',
	        		'left': '-5000px'	        		
	        	} );
	        	
		        // Get the size and position of the left menu
		        var leftCoords = left.getCoordinates( );
	        	
	        	right.setStyle( 'left', leftCoords['width'] );

	            // Get the size and position of the right side menu
	            var rightCoords = right.getCoordinates( );
	
	            // Are the two menus different heights?
	            if ( rightCoords['height'] != leftCoords['height'] )
	            {
	
	                var menuHeight = null;
	
	                // Set the height of the shorter menu to the height of
	                // the taller menu
	                if ( rightCoords['height'] > leftCoords['height'] )
	                {
	
	                    menuHeight = rightCoords['height'];
	
	                }
	                else
	                {
	
	                    menuHeight = leftCoords['height'];
	
	                }
	
	                // If we've worked out a height, assign both menus to
	                // have the same hight
	                if ( $defined( menuHeight ) )
	                {
	
	                    left.setStyle( 'height', menuHeight );
	                    right.setStyle( 'height', menuHeight );
	
	                }
	
	            }

	        	// Reset the styles for correct display
	        	left.setStyles( { 
	        		'display': '',
	        		'left': 0
	        	} );
	        	right.setStyles( { 
	        		'display': ''
	        	} );
	        	
	        }
	        else
	        {
	
	            // There is no right side menu so we need to put a border on
	            // the right side of the left side menu
	            left.setStyle( 'border', 'solid 4px #FFCC00' );
	        }
	
	    }


    });

});

