function fnFormatDetails(oTable, nTr) {
	var aData = oTable.fnGetData(nTr);

	var gameid = aData[2];

	var sOut = $.ajax({
		type: "GET",
		async: false,
		url: '/get_game_details.php?gameid='+gameid,
		cache: false
		
	});
		
	return sOut.responseText;
}

$(document).ready(function() {

	var nCloneTh = document.createElement( 'th' );
	var nCloneTd = document.createElement( 'td' );
	nCloneTd.innerHTML = '<img src="/js/DataTables-1.8.1/examples/examples_support/details_open.png">';
	nCloneTh.setAttribute("width", "1%");
	
//	var Details = document.createTextNode('Details');
//	nCloneTh.appendChild(Details);

	$('#games thead tr').each(function() {
		this.insertBefore(nCloneTh, this.childNodes[0]);
	});

	$('#games tbody tr').each(function() {
		this.insertBefore(nCloneTd.cloneNode(true), this.childNodes[0]);
	});

	var oTable = $('#games').dataTable({
		"aoColumns": [
			{ "bSortable": false, "sClass": "center", "sWidth": "1%" },
			{ "sWidth": "1%", "sClass": "center"},
			{ "sWidth": "1%", "sClass": "center", "bVisible": false},
			null,
			null,
			{ "sWidth": "1%"},
			null
		],
		"bAutoWidth": false,
		"bProcessing": true,
		"bJQueryUI": true,
		"aaSorting": [[6, 'asc'], [4, 'desc']]

	});

	$('#games tbody td img').live('click', function() {
		var nTr = this.parentNode.parentNode;
		if  ( this.src.match('details_close')) {
			this.src = "/js/DataTables-1.8.1/examples/examples_support/details_open.png";
			oTable.fnClose(nTr);
		} else {
			this.src = "/js/DataTables-1.8.1/examples/examples_support/details_close.png";
			oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
		}
	});

	
});

