﻿function Button( element, norm_img, over_img, down_img, width, height, action )
{
	this.m_oElement		= (typeof( element ) == 'string')? document.getElementById( element ) : element;
	
	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_strAction	= action;
	
	this.m_oNormImg = null;
	this.m_oOverImg = null;
	this.m_oDownImg = null;
	
	this.Create();
}

Button.prototype.Create = function()
{
	var me = this;
	
	this.m_oNormImg = new Image(); this.m_oNormImg.src = this.m_strNormImg;
	this.m_oOverImg = new Image(); this.m_oOverImg.src = this.m_strOverImg;
	this.m_oDownImg = new Image(); this.m_oDownImg.src = this.m_strDownImg;
	
	if( this.m_oElement != null )
	{
		this.m_oElement.style.width		= this.m_iWidth+'px';
		this.m_oElement.style.height	= this.m_iHeight+'px';
		
		this.m_oElement.onmousedown		= function(e){ me.OnMouseDown(); }
		this.m_oElement.onmouseup		= function(e){ me.OnMouseUp(); }
		this.m_oElement.onmouseover		= function(e){ me.OnMouseOver(); }
		this.m_oElement.onmouseout		= function(e){ me.OnMouseOut(); }
		this.m_oElement.onclick			= function(e){ me.OnClick(); }
		
		this.m_oElement.src				= this.m_oNormImg.src;
	}
	else
		alert( 'Failed to create rollover button.' );
}

Button.prototype.OnMouseDown = function()
{
	this.m_oElement.src = this.m_oDownImg.src;
}

Button.prototype.OnMouseUp = function()
{
	this.m_oElement.src = this.m_oOverImg.src;
}

Button.prototype.OnMouseOver = function()
{
	this.m_oElement.src = this.m_oOverImg.src;
}

Button.prototype.OnMouseOut = function()
{
	this.m_oElement.src = this.m_oNormImg.src;
}

Button.prototype.OnClick = function()
{
	if( this.m_strAction == '' )
		return;
		
	if( typeof( this.m_strAction ) == 'string' )
		eval( this.m_strAction );
	else
		this.m_strAction();
}
