function EstimateCount( name, width )
{
    var list_div = document.getElementById(name);
    var list_width = list_div.parentNode.offsetWidth;
    
    return Math.floor( list_width / width );
}

function ResizeList( name, style, width, ml, mr, lines, start )
{
    var list_div = document.getElementById(name);
    var list_width = list_div.parentNode.offsetWidth;
    
    var theRules;
    if (document.styleSheets[0].cssRules)
	    theRules = document.styleSheets[0].cssRules;
    else if (document.styleSheets[0].rules)
	    theRules = document.styleSheets[0].rules;
    
    var s = theRules[style].style;

    var full_count = Math.floor( list_width / width );
    if( full_count < 1 )
        full_count = 1;
    var left = Math.floor( ( list_width % width ) / ( 2 * full_count ) );
    
    s.paddingLeft = ml + left + 'px';
    s.paddingRight = mr + left + 'px';
    
    var children = list_div.getElementsByTagName('div');
    var children_count = 0;
    var i;
    for( i = 0; i < children.length; i++ )
    {
        if( i < start || children_count >= lines * full_count )
        {
            children[ i ].style.display = 'none';
        }
        else
        {    
            if( children_count < lines * full_count )        
            {
                children[ i ].style.display = 'block';
                children_count++;
            }
        }
    }
    
    return children_count;
}

function ResizeGameList()
{
    var list_lines = 3;
    var bigtop_count = ResizeList( 'list_top_games_div', 1, 145 + 10, 5, 5, 1, 0 );
    var list_start = Math.max( bigtop_count - start_index, 0 );
    var visible_count = ResizeList( 'more_top_games_div', 0, 75 + 10, 5, 5, list_lines, list_start);
    
    var prev_link = document.getElementById( 'ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolder_GameListWindow_ctl01_PrevLink' );
    var next_link = document.getElementById( 'ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolder_GameListWindow_ctl01_NextLink' );
    
    if( start_index <= bigtop_count )
    {
        prev_link.style.display = 'none';
    }
    else
    {
        var full_count = list_lines * EstimateCount( 'more_top_games_div', 75 + 10 );
    
        prev_link.style.display = 'inline';
        prev_link.href = navigate_url + Math.max( start_index - full_count, 0 );
    }
    
    if( list_start + visible_count + start_index >= total_games )
    {
        next_link.style.display = 'none';
    }
    else
    {
        next_link.style.display = 'inline';
        next_link.href = navigate_url + Math.min( start_index + list_start + visible_count, total_games );
    }    
}



