function player_data( id ) {
	var result = null;
	$j.ajax({
		async: false,
		url: "/profil.php?op=datafeed&pl_id=" + id,
		dataType:'json',
		success: function(data) {
			result = data;
		}
	});
	return result;
}

function show_player( id ) { 
	var data = player_data( id ); 

	$j.jqplot.config.enablePlugins = true;

	$j('#player-tabs').tabs();
		
	function pointsDetails (ev, gridpos, datapos, neighbor, plot) {
		if (neighbor == null) {
			$j('#pointDetailsTip').fadeOut().empty();
			isShowing = false;
		}
		if (neighbor != null) {
			if ($j('#pointDetailsTip').is(':hidden')) {
				var d = new Date();
				var p_text = "punktów";
				if ( neighbor.data[1] == 1 ) {
					p_text = "punkt";
				} else if ( 1 < neighbor.data[1] && neighbor.data[1] < 5 ) {
					p_text = "punkty";				
				}
				var myText = neighbor.data[1] + " " + p_text + " w " + neighbor.data[0] + " kolejce";  
				$j('#pointDetailsTip').html(myText).css({left:gridpos.x, top:gridpos.y}).fadeIn();
			}
		}
	}

	$j.jqplot.eventListenerHooks.push(['jqplotMouseMove', pointsDetails]);
	
	var player_chart = $j.jqplot('player_chart', [data], {
		seriesColors:['#E9C63A'],
		axes: {
			grid: {
				background: '#E9C63A',
				gridLineColor: '#1A1510',
				gridLineWidth: 1,
				shadow: false
			},
      xaxis: {
				label: 'Kolejka spotkań',
      	renderer: $j.jqplot.CategoryAxisRenderer,
				borderWidth: 1,
				borderColor:'#E9C63A',
				ticks:['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX'],
				tickOptions:{
					showGridline: false
				},
				labelOptions:{
					fontFamily:'Trebuchet MS',
					fontSize: '11pt'
				}
      },
			yaxis: {
				borderWidth: 1,
				borderColor: '#E9C63A',
				min: 0,
				labelOptions:{
					fontFamily:'Trebuchet MS',
					fontSize: '11pt'
				},
				tickOptions:{formatString:'%d'}
			}
		}
  });
	
	$j('#player-tabs').bind('tabsshow', function(event, ui) {
	  if (ui.index == 1 && player_chart._drawCount == 0) {
	    player_chart.replot();
			$j('#player_chart').append('<div id="pointDetailsTip" style="position:absolute;display:none;background:#E5DACA;padding:4px;"></div>');
	  }
	});	
};
