﻿function PhButton( norm_img, over_img, down_img, width, height, action_script )
{
	this.m_strNormImg		= norm_img;
	this.m_strOverImg		= over_img;
	this.m_strDownImg		= down_img;
	
	this.m_iWidth			= width;
	this.m_iHeight			= height;
	
	this.m_strActionScript	= action_script;
	
	this.m_oImage			= null;

	this.Create();
}

PhButton.prototype = new PhControl();

PhButton.prototype.Create = function()
{
	var me = this;
	
	var t1 = new Image(); t1.src = this.m_strNormImg;
	var t2 = new Image(); t2.src = this.m_strOverImg;
	var t3 = new Image(); t3.src = this.m_strDownImg;
	
	this.m_oContainer	= document.createElement( 'div' );
	this.m_oImage		= document.createElement( 'div' );
	
	if( this.m_oContainer != null && this.m_oImage != null )
	{	
		this.m_oImage.className	= 'png';
		
		this.m_oImage.style.width			= this.m_iWidth+'px';
		this.m_oImage.style.height			= this.m_iHeight+'px';
		this.m_oImage.style.backgroundImage = 'url('+this.m_strNormImg+')';
		
		this.m_oImage.onmousedown	= function(e){ me.MouseDown(); }
		this.m_oImage.onmouseup		= function(e){ me.MouseUp(); }
		this.m_oImage.onmouseover	= function(e){ me.MouseOver(); }
		this.m_oImage.onmouseout	= function(e){ me.MouseOut(); }
		this.m_oImage.onclick		= function(e){ me.ExecuteActionScript(); }
	
		this.m_oContainer.style.width		= this.m_iWidth+'px';
		this.m_oContainer.style.height		= this.m_iHeight+'px';
		this.m_oContainer.style.position 	= 'relative';
		this.m_oContainer.style.cursor		= 'pointer';
		this.m_oContainer.appendChild( this.m_oImage );
	}
	else
	{
		alert( 'failed to create instance of Simple Button Widget object' );
	}
}

PhButton.prototype.MouseDown = function()
{
	this.m_oImage.style.backgroundImage = 'url('+this.m_strDownImg+')';
}

PhButton.prototype.MouseUp = function()
{
	this.m_oImage.style.backgroundImage = 'url('+this.m_strOverImg+')';
}

PhButton.prototype.MouseOver = function()
{
	this.m_oImage.style.backgroundImage = 'url('+this.m_strOverImg+')';
	
}

PhButton.prototype.MouseOut = function()
{
	this.m_oImage.style.backgroundImage = 'url('+this.m_strNormImg+')';
}

PhButton.prototype.SetActionScript = function( action_script )
{
	this.m_strActionScript = action_script;
}

PhButton.prototype.ExecuteActionScript = function()
{
	if( typeof( this.m_strActionScript ) == 'string' )
		eval( this.m_strActionScript );
	else
		this.m_strActionScript();
}

PhButton.prototype.SetMargins = function( top, right, bottom, left )
{
	this.m_oContainer.style.margin = top+'px '+right+'px '+bottom+'px '+left+'px';
}

PhButton.prototype.DisableClick = function()
{
	this.m_oContainer.style.cursor = '';
	
	this.m_oImage.onmousedown	= null;
	this.m_oImage.onmouseup		= null;
	this.m_oImage.onclick		= null;
}