﻿function PhPortrait()
{
	this.SearchResult		= null;
	
	this.m_oContainer		= null;
	this.m_oLowerLeftDiv	= null;
	this.m_oLowerRightDiv	= null;
	this.m_oImage			= null;
	this.m_oCaption			= null;
	this.m_fpSelected		= null;
	this.m_oSelected		= false;
	
	this.InitObject();
}

PhPortrait.prototype = new PhControl();

PhPortrait.prototype.InitObject = function()
{
	var me		= this;
	
	this.m_oImage			= document.createElement( 'img' );
	this.m_oCaption			= document.createElement( 'div' );
	this.m_oContainer		= document.createElement( 'div' );
	
	this.m_oContainer.className	= 'portrait_container';
	this.m_oCaption.className	= 'portrait_caption';
	
	this.m_oImage.className		= 'portrait_image';
	this.m_oImage.onclick		= function()
	{
		if( !me.m_bSelected )
		{
			me.OnSelect();
		}
		else
		{
			me.OnDeselect( true );
		}
	};
	
	this.m_oContainer.style.cursor = 'pointer';
	this.m_oContainer.appendChild( this.m_oImage );
	this.m_oContainer.appendChild( this.m_oCaption );
	
	g_oClient.DisableSelection( this.m_oImage );
	g_oClient.DisableSelection( this.m_oContainer );
}

PhPortrait.prototype.SetSelectedCallback = function( cb )
{
	this.m_fpSelected = cb;
}

PhPortrait.prototype.SetSearchResult = function( search_result )
{		
	var caption = '';
	var id		= '';
	
	this.SearchResult			= search_result;
	this.m_oImage.src			= search_result.file_path;
	this.m_oImage.width			= search_result.width;
	this.m_oImage.height		= search_result.height;
	
	id = search_result.card_id.toString();
	
	while( id.length < 4 )
	{
		id = '0'+id;
	}
	
	switch( search_result.status_id )
	{
		case 1:
			caption = 'not for sale';
			break;
			
		case 2:			
		case 3:
		case 4:
			caption = (search_result.price == 0)? 'make an offer' : '#'+id+' - $'+search_result.price.toFixed(2);
			break;
			
		case 5:
			caption = 'sold';
			break;
			
		case 6:
			caption = 'traded';
			break;
			
		case 7:
			caption = 'lost';
			break;
	}	
	
	this.m_oCaption.innerHTML	= caption;
	
	/*
	if( search_result.status_id != 2 && 
		search_result.status_id != 3 && 
		search_result.status_id != 4 )
	{
		var orb = document.createElement( 'img' )
		orb.src			= 'images/red_orb.png';
		orb.width		= 37;
		orb.height		= 37;
		orb.className	= 'png';
		
		orb.style.position = 'absolute';
		orb.style.top		= search_result.height-16+'px';
		orb.style.left		= search_result.width-16+'px';
		orb.style.zIndex	= '1';
		
		this.m_oContainer.appendChild( orb );
	}
	*/
}

PhPortrait.prototype.SetPosition = function( x, y )
{
	this.m_oContainer.style.left	= x+'px';
	this.m_oContainer.style.top		= y+'px';
}

PhPortrait.prototype.OnSelect = function()
{	
	if( this.m_fpSelected != null )
		this.m_fpSelected( this );
}
