JQ(document).ready(function() {
    // adjust athlete name font sizes
    resizeNames('.primary .name span');
    
    //hack to get names centered vertically in IE
    if (navigator.appName=="Microsoft Internet Explorer"){
        centerNames('.primary .name');
    }

    Cufon.now();
    Cufon.replace('li.primary a', { fontFamily: 'ArnoPro', hover: true });
    Cufon.replace('#newsFeed h2 a', { fontFamily: 'ArnoPro', hover: true});
    Cufon.replace('a.viewAll', { fontFamily: 'Futura', hover: true});
    Cufon.replace('a#hide-view', { fontFamily: 'Futura'});
});

var team = (function() {
    
    JQ('#athlete-list li').mouseenter(          
        function(){
            var fadingIn = JQ('#'+JQ(this).attr('id')+'-action-shot');
            var fadingOut = JQ('#athlete-action-shot .show');

            if ( fadingIn.attr('id') != fadingOut.attr('id') ) {
                fadingOut.toggleClass('show').toggleClass('hide');
                fadingIn.fadeIn(250).toggleClass('show').toggleClass('hide');
                fadingOut.fadeOut('fast');
            }
        }
    );    
}());

function resizeNames(e){
    JQ(e).each( function() {
        boxWidth = JQ(this).parent().parent().width();
        nameWidth = JQ(this).width();
       
        while (nameWidth > 106) {
            var newSize = JQ(this).css('fontSize').replace('px','') - 1
            JQ(this).css('fontSize', newSize+'px' );
            nameWidth = JQ(this).width();
        }
    });
}

function centerNames(e){
    JQ(e).each( function() {
        JQ(this).parent().css('width','120px');
        nameHeight = JQ(this).height();
        JQ(this).css('top',((104-nameHeight)/2)+'px')
    });
}
