function PokerPlayer( gameContext )
{
	// Instance variables
	if ( !gameContext )
	{
		alert( 'No gameContext passed to PokerPlayer constructor' );
	}
	this.gameContext = gameContext;
	this.buyIn = 0;
	this.position = -1;
	
	// DOM objects
	this.tableRow = document.createElement( 'tr' );
	this.objNameCell = document.createElement( 'td' );
	this.objBuyInText = document.createTextNode( '' );
	var objBuyInCell = document.createElement( 'td' );
	objBuyInCell.appendChild( this.objBuyInText );
	objBuyInCell.className = 'buyin';
	this.objPrizeText = document.createTextNode( '' );
	var objPrizeCell = document.createElement( 'td' );
	objPrizeCell.appendChild( this.objPrizeText );
	var objActionsCell = document.createElement( 'td' );
	objActionsCell.className = 'action';
	this.tableRow.appendChild( this.objNameCell );
	this.tableRow.appendChild( objBuyInCell );
	this.tableRow.appendChild( objPrizeCell );
	this.tableRow.appendChild( objActionsCell );

	this.createButton = function( caption, clickHandler )
	{
		var newButton = document.createElement( 'input' );
		newButton.context = this;
		newButton.type = 'button';
		newButton.value = caption;
		newButton.onclick = clickHandler;
		return newButton;
	}
	
	this.objBuyInDecrease = this.createButton( '- ' + this.gameContext.currency, function() 
	{ 
		this.context.alterBuyIn( -this.context.gameContext.buyIn ); 
	} );
	objActionsCell.appendChild( this.objBuyInDecrease );
	
	this.objBuyInIncrease = this.createButton( '+ ' + this.gameContext.currency, function() 
	{ 
		this.context.alterBuyIn( this.context.gameContext.buyIn ); 
	} );
	objActionsCell.appendChild( this.objBuyInIncrease );

	this.objOut = this.createButton( 'out', function() 
	{ 
		this.context.gameContext.setPlayerIsPlaying( this.context, false ); 
	} );
	objActionsCell.appendChild( this.objOut );

	this.objIn = this.createButton( 'in', function() 
	{ 
		this.context.gameContext.setPlayerIsPlaying( this.context, true ); 
	} );		
	this.objIn.style.display = 'none';
	objActionsCell.appendChild( this.objIn );
	
	this.objRemove = new Image();
	this.objRemove.src = '/core/images/icons/trash.gif';
	this.objRemove.className = 'actionImage';
	this.objRemove.context = this;
	this.objRemove.onclick = function() 
	{ 
		this.context.gameContext.removePlayer( this.context ); 
	};
	objActionsCell.appendChild( this.objRemove );

	this.alterBuyIn = function(amount) 
	{
		if ( this.buyIn + amount < 0 )
		{
			return false;
		}		
		this.buyIn += amount;
		this.gameContext.prizePool.update();
		this.gameContext.onBuyInAltered();
		this.refreshAppearance();
		return true;
	};
	
	this.setIsPlaying = function(isPlaying) 
	{
		this.refreshAppearance();
	};
	
	this.refreshAppearance = function()
	{
		var isPlaying = this.position == -1;
		this.objBuyInText.nodeValue = this.buyIn > 0 ? this.gameContext.currency + this.buyIn : '-';
		var positionText = '-';
		if ( this.position != -1 )
		{
			positionText = getPositionString( this.position + 1 );
			var placePaidAmounts = this.gameContext.prizePool.cachedPlacePaidAmounts;
			if ( placePaidAmounts && placePaidAmounts[ this.position ] )
			{
				positionText += " (" + this.gameContext.currency + placePaidAmounts[ this.position ] + ")";
			}
		}
		this.objPrizeText.nodeValue = positionText;
		this.objBuyInDecrease.disabled = this.buyIn == 0;
		this.objIn.style.display = isPlaying ? 'none' : 'inline';
		this.objOut.style.display = isPlaying ? 'inline' : 'none';
		// CSS Class
		this.tableRow.className = isPlaying ? 'inPlay' : 'outOfGame';
		if ( this.buyIn == 0 )
		{
			appendClassName( this.tableRow, 'unpaid' );
		}
		else if ( this.buyIn > this.gameContext.buyIn )
		{
			appendClassName( this.tableRow, 'rebought' );
		}
	};
	
	this.toString = function()
	{
		return this.name + ": " +  this.gameContext.currency + this.buyIn;
	};
	
	this.toXml = function( documentContext )
	{
		if ( !documentContext )
		{
			alert( "No documentContext passed to PokerPlayer.toXML()" );
			return null;
		}
		var pokerplayer = documentContext.createElement( 'pokerplayer' );
		pokerplayer.setAttribute( 'name', this.name );
		pokerplayer.setAttribute( 'buyin', this.buyIn );
		pokerplayer.setAttribute( 'position', this.position );
		var placePaidAmounts = this.gameContext.prizePool.cachedPlacePaidAmounts;
		if ( placePaidAmounts && placePaidAmounts[ this.position ] )
		{
			pokerplayer.setAttribute( 'prize', placePaidAmounts[ this.position ] );
		}
		return pokerplayer;
	}
	
	this.initFromXml = function( xml )
	{
		this.name = xml.getAttribute( 'name' );
		this.buyIn = parseInt( xml.getAttribute( 'buyin' ) );
		this.position = parseInt( xml.getAttribute( 'position' ) );
		this.objNameCell.appendChild( document.createTextNode( this.name ) );
		this.refreshAppearance();
	}
	
	this.initWithValues = function( name )
	{
		this.name = name;
		this.objNameCell.appendChild( document.createTextNode( this.name ) );
		// Update text 
		this.refreshAppearance();
	}
}