// JavaScript Document

function Button( key, value, image )
{
	this.key = key;
	this.value = value;
	this.up = new Image();
	this.up.src = image;
	this.over = new Image();
	this.over.src = image.replace( /\.(\w*)$/, "_f2.$1" );
	this.down = new Image();
	this.down.src = image.replace( /\.(\w*)$/, "_f3.$1" );
	this.overwhiledown = new Image();
	this.overwhiledown.src = image.replace( /\.(\w*)$/, "_f4.$1" );
	var p = image.replace( /\.\w*$/, "" );
	var ps = p.split( "/" );
	this.id = ps[ps.length-1];
	this.action = "true";
	this.style = "";
	this.map = null;
}

Button.prototype.setAction = function( action )
{
	this.action = action;
}

Button.prototype.setStyle = function( style )
{
	this.style = style;
}

Button.prototype.setValue = function( value )
{
	this.value = value;
}

Button.prototype.setMap = function( map )
{
	this.map = map;
	this.map.setParent( this );
}

function swapImage( id, src )
{
	var i = document.getElementById( id );
	i.src = src;
}

Button.prototype.preLoad = function()
{
	var d = document;
	if ( !d.TS_p ) { d.TS_p = new Array(); }
	var j = d.TS_p.length;
	d.TS_p[j++] = this.up;
	d.TS_p[j++] = this.over;
	d.TS_p[j++] = this.down;
	d.TS_p[j++] = this.overwhiledown;
}

Button.prototype.toDown = function()
{
	var markup = 
		"<a class='" + this.style + "' href='' " +
		"onClick=\"return false;\" " +
		"onMouseOver=\"swapImage('" + this.id + "','" + this.overwhiledown.src + "');\" " +
		"onMouseOut=\"swapImage('" + this.id + "','" + this.down.src + "');\" " +
		">" + 
		"<img src='" + this.down.src + "' id='" + this.id + "' " +
		"alt='" + this.key + "' border='0'>" +
		 "</a>";	 
	 return markup;
}

Button.prototype.toUp = function()
{
	if ( this.map == null )
	{
		return this._toUp();
	}
	else
	{
		return this.toMap();
	}
}

Button.prototype._toUp = function()
{
	var markup =													  
		"<a class='" + this.style + "' href='" + this.value + "' " +
		"onClick=\"return " + this.action + ";\" " +
		"onMouseOver=\"swapImage('" + this.id + "','" + this.over.src + "');\" " +
		"onMouseOut=\"swapImage('" + this.id + "','" + this.up.src + "');\" " +
		">" + 
		"<img src='" + this.up.src + "' id='" + this.id + "' " +
		"alt='" + this.key + "' border='0'" +
		">" +
		 "</a>";
	
	return markup;
}

Button.prototype.toMap = function()
{
	var markup =													  
		"<a class='" + this.style + "' href='" + this.value + "' " +
		"id='a." + this.id + "' " + 
		"onClick=\"return false;\" " +
		"onMouseOver=\"swapImage('" + this.id + "','" + this.over.src + "');\" " +
		"onMouseOut=\"swapImage('" + this.id + "','" + this.up.src + "');\" " +
		">" + 
		"<img src='" + this.up.src + "' id='" + this.id + "' " +
		"alt='" + this.key + "' border='0'" +
		( ( this.map == null ) ? "" : "usemap='#" + this.map.name + "'" ) +
		">" +
		 "</a>";
	
	markup += this.map.toMarkup();
	
	return markup;
}

Button.prototype.toDisabled = function()
{
	var markup =
		"<img class='" + this.style + "' style='visibility:hidden' src='" + this.up.src + "' alt='' border='0'>";
		
	return markup;
}

