/* Functions to strip out the commas when sorting numeric columns */
jQuery.fn.dataTableExt.oSort['numeric-commas-asc']  = function(a,b) {
	var x = (a == "-") ? 0 : a.replace( /,/, "" );
	var y = (b == "-") ? 0 : b.replace( /,/, "" );
	x = parseFloat( x );
	y = parseFloat( y );
	return ((x < y) ? -1 : ((x > y) ?  1 : 0));
};

jQuery.fn.dataTableExt.oSort['numeric-commas-desc'] = function(a,b) {
	var x = (a == "-") ? 0 : a.replace( /,/, "" );
	var y = (b == "-") ? 0 : b.replace( /,/, "" );
	x = parseFloat( x );
	y = parseFloat( y );
	return ((x < y) ?  1 : ((x > y) ? -1 : 0));
};

jQuery.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
	var x = a.replace( /<.*?>/g, "" );
	var y = b.replace( /<.*?>/g, "" );
	x = parseFloat( x );
	y = parseFloat( y );
	return ((x < y) ? -1 : ((x > y) ?  1 : 0));
};

jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
	var x = a.replace( /<.*?>/g, "" );
	var y = b.replace( /<.*?>/g, "" );
	x = parseFloat( x );
	y = parseFloat( y );
	return ((x < y) ?  1 : ((x > y) ? -1 : 0));
};

$(document).ready(
    function()
    {
        $('#doctorsTable').dataTable({
            /* Show 15 results per page */
            "iDisplayLength": 15,
            
            /* Show detailed pagination controls */
            "sPaginationType": "full_numbers",

            /* Initially sort by influence */
            "aaSorting": [[ 3, "desc" ]],
            
            /* Influence, Tweets, Followers, Retweets, should sort descending on first click */
            "aoColumns": [
                null,
                null,
                null,
                { "sType": "num-html", "asSorting": [ "desc", "asc" ] },
                { "sType": "numeric-commas", "asSorting": [ "desc", "asc" ] },
                { "sType": "numeric-commas", "asSorting": [ "desc", "asc" ] },
                { "sType": "numeric-commas", "asSorting": [ "desc", "asc" ] }
            ]

        });
    }
);
