﻿function PhImgButton( 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();
}

PhImgButton.prototype = new PhControl();

PhImgButton.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( 'img' );
	
	if( this.m_oContainer != null && this.m_oImage != null )
	{	
		//this.m_oImage.className	= 'png';
		
		this.m_oImage.setAttribute( 'width', this.m_iWidth+'px' );
		this.m_oImage.setAttribute( 'height', this.m_iHeight+'px' );
		this.m_oImage.setAttribute( 'src', 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.cursor		= 'pointer';
		
		//the below code causes problems in IE>
		//this.m_oContainer.style.position 	= 'relative';
		//this.m_oContainer.style.left		= '0px';
		//this.m_oContainer.style.top		= '0px';
		
		this.m_oContainer.appendChild( this.m_oImage );
	}
	else
	{
		alert( 'failed to create instance of Simple Button Widget object' );
	}
}

PhImgButton.prototype.MouseDown = function()
{
	this.m_oImage.src = this.m_strDownImg;
}

PhImgButton.prototype.MouseUp = function()
{
	this.m_oImage.src = this.m_strOverImg;
}

PhImgButton.prototype.MouseOver = function()
{
	this.m_oImage.src = this.m_strOverImg;
	
}

PhImgButton.prototype.MouseOut = function()
{
	this.m_oImage.src = this.m_strNormImg;
}

PhImgButton.prototype.SetActionScript = function( action_script )
{
	this.m_strActionScript = action_script;
}

PhImgButton.prototype.ExecuteActionScript = function()
{
	if( typeof( this.m_strActionScript ) == 'string' )
		eval( this.m_strActionScript );
	else
		this.m_strActionScript();
}

PhImgButton.prototype.SetMargins = function( top, right, bottom, left )
{
	this.m_oContainer.style.margin = top+'px '+right+'px '+bottom+'px '+left+'px';
}