/**
 * @author simon.gilhooly
 */
$(function(){
    $.tablesorter.addParser({ 
        // set a unique id 
        id: 'highscore', 
        is: function(s) { 
            // return false so this parser is not auto detected 
            return false; 
        }, 
        format: function(s) { 
            // format your data for normalization 
            return s.replace("*",""); 
        }, 
        // set type, either numeric or text 
        type: 'numeric' 
    }); 

	var proxy = 'php_proxy.php';
	var params = $.param({
		url: 'http://www.cavaliers-cc-forum.org.uk/v3/stats_bat.aspx',
		mode: 'native'
	});

	$('#batting').load(proxy + '?' + params + ' #Averages_Batting_Grid', function(){
		$('<thead><tr><th>Name</th><th>Played</th><th>Innings</th><th>NO</th><th>Runs</th><th>Average</th><th>50s</th><th>100s</th><th>High</th></tr></thead>').insertBefore('#Averages_Batting_Grid tbody');
//		$('<thead />').insertBefore('tbody');
//		$(this).find('tr:first').remove().appendTo('thead');
		$(this).find('tbody tr:first').remove();
		$('#Averages_Batting_Grid').addClass('tablesorter');

//		$(this).find('tr:first').addClass('head');
		$(this).children('table').css('width', '98%');

	    
	    $('#Averages_Batting_Grid').tablesorter({
            headers: { 
                8: { 
                    sorter:'highscore' 
                } 
            }
        });
	});

	var params = $.param({
		url: 'http://www.cavaliers-cc-forum.org.uk/v3/stats_bowl.aspx',
		mode: 'native'
	});

	$('#bowling').load(proxy + '?' + params + ' #Averages_Bowling_Grid', function(){
		$('<thead><tr><th>Name</th><th>O</th><th>M</th><th>R</th><th>W</th><th>Ave</th><th>Econ</th><th>5W</th><th>10W</th><th>Hatrick</th><th>Best</th></tr></thead>').insertBefore('#Averages_Bowling_Grid tbody');
		$(this).find('tbody tr:first').remove();
		$('#Averages_Bowling_Grid').addClass('tablesorter');


//		$(this).find('tr:first').addClass('head');
		$(this).children('table').css('width', '98%');

	    $('#Averages_Bowling_Grid').tablesorter({
            headers: { 
                10: { 
                    sorter:false 
                } 
            }
        });
	});


});
