var crossFadeTabs = function( selector ) {
    var list            = $( selector );

    var heights     = {};
    var labels      = $$( "#"+selector+" dt" );
    var panes       = $$( "#"+selector+" dd" );
    var tabHeight = labels[0].getCoordinates().height;
    
    var fx              = new Fx.Elements( panes, { duration: 500 } );

    panes.each( function( pane, i ) {
        pane.addClass( 'pane' );
        var o = {};

        heights[i] = pane.getCoordinates().height;
        if( i != 0 ) {
            o[i] = { opacity : 0 };
            fx.set( o );
            pane.setStyle( 'visibility', 'hidden' );
        } else {
            list.setStyle( 'height', heights[i] + tabHeight );
            pane.setStyle( 'height', heights[i] );
        }
    });

    labels.each( function( label, labelIndex ) {
        label.addClass( 'label' );      
        label.addEvent( "click", function( event ) {
            label.addClass( 'selected' );
            var o = {};
            labels.each( function( oldLabel, oldLabelIndex ) {
                
                if( labelIndex != oldLabelIndex && oldLabel.hasClass( 'selected' ) ) {
                    
                    oldLabel.removeClass( 'selected' );
                    o[ oldLabelIndex ] = { opacity : 0 };
                    // this will account for tabs that have thier content changed.
                    o[ labelIndex ] = { opacity : 1, height : [ heights[ oldLabelIndex ], panes[ labelIndex ].getCoordinates().height ] };                  
                    if (heights[ oldLabelIndex ] < heights[ labelIndex ]) {
                        list.setStyle( 'height', heights[ labelIndex ] + tabHeight );
                        fx.start( o );
                    } else {
                        fx.start( o ).chain(function() {
                            list.setStyle( 'height', heights[ labelIndex ] + tabHeight );});
                    }               
                    
                }
            });
        });
        if( labelIndex == 0 ) { 
            label.addClass( 'selected' ); 
        }
    });

};