/*
**	StorCOMM, Inc.
**	Copyright 2000. All rights reserved.
**
**	Button functions used to animate button functionality. The bitmap images
**	used to represent the various states of a button can be changed for
**	various button events. The states supported include normal, hot (mouse is
**	over the button), push, and gray. The button should be initialized as
**	the page that uses the buttons is loaded.
**
**	Author: S. Treiber
**	Date:	Jan/2000
*/

function buttonBag( sPath )
{
	this.start = 7;
	this.size = 7;
	this.count = 0;
	this.path = sPath;
	
	this.newButton = buttonbagNew;
	this.length = buttonbagGetCount;
	this.initialize = buttonbagInitialize;
	
}	// buttonBag

function buttonbagNew( sId, sLinkId, bNormal, bHot, bPush, bGray )
{
	var imgNormal = null;
	if ( bNormal )
	{
		imgNormal = new Image();
		imgNormal.src = this.path + sId + ".jpg";
	}
	
	var imgHot = null;
	if ( bHot )
	{
		imgHot = new Image();
		imgHot.src = this.path + sId + "_hot.jpg";
	}
	
	var imgPush = null;
	if ( bPush )
	{
		imgPush = new Image();
		imgPush.src = this.path + sId + "_push.jpg";
	}
	
	var imgGray = null;
	if ( bGray )
	{
		imgGray = new Image();
		imgGray.src = this.path + sId + "_gray.jpg";
	}
	
	// Create an image object using the specified id as
	// an identifier. Assign the source location for the
	// image(s) used to manipulate the button.
	buttonBag[ this.size ] = sLinkId;
	buttonBag[ sLinkId ] = new button( sId, sLinkId, imgNormal, imgHot, imgPush, imgGray );
	this.count++;
 	this.size++;

}	// buttonbagNew

function buttonbagGetCount()
{
	return this.count();
}	// buttonbagGetCount

function buttonbagInitialize()
{
	for ( var i=0; i < this.count; ++i )
	{
//		buttonBag[ this.start+i ].initialize();
		
		var s = buttonBag[ this.start+i ];
		buttonBag[ s ].initialize();
	}
	
}	// buttonbagInitialize

function button( sId, sLinkId, imgNormal, imgHot, imgPush, imgGray )
{
	this.sID = sId;
	this.sLinkID = sLinkId;
	this.imgNormal = imgNormal;
	this.imgHot = imgHot;
	this.imgPush = imgPush;
	this.imgGray = imgGray;
	this.bEnabled = true;
	
	this.fxMouseOver = null;
	this.fxMouseOut = null;
	this.fxMouseUp = null;
	this.fxMouseDown = null;
	
	this.OnMouseOver = buttonOnMouseOver;
	this.OnMouseOut = buttonOnMouseOut;
	this.OnMouseUp = buttonOnMouseUp;
	this.OnMouseDown = buttonOnMouseDown;
	
	this.initialize = buttonInitialize;
	this.enable = buttonEnable;
	this.isEnabled = buttonIsEnabled;

	this.imageNormalSet = buttonNormal;
	this.imageHotSet = buttonHot;
	this.imagePushSet = buttonPush;
	this.imageGraySet = buttonGray;
	
}	// button

function buttonInitialize()
{
	var link = objectGet( self, this.sLinkID );
	if ( link )
	{
		if ( link.onmouseover ) this.fxMouseOver = link.onmouseover;
		if ( link.onmouseout ) this.fxMouseOut = link.onmouseout;
		if ( link.onmouseup ) this.fxMouseUp = link.onmouseup;
		if ( link.onmousedown ) this.fxMouseDown = link.onmousedown;
	}

	this.enable( false );
	
}	// buttonInitialize

function buttonEnable( bEnable )
{
	if ( bEnable == null ) bEnable = true;
	if ( this.bEnable == bEnable ) return;

	var link = objectGet( self, this.sLinkID );
	if ( bEnable )
	{
		if ( link )
		{
			link.onmouseover = this.OnMouseOver;
			link.onmouseout = this.OnMouseOut;
			link.onmouseup = this.OnMouseUp;
			link.onmousedown = this.OnMouseDown;
		}
		
		this.imageNormalSet();
	}
	else
	{
		if ( link )
		{
			link.onmouseover = null;
			link.onmouseout = null;
			link.onmouseup = null;
			link.onmousedown = null;
		}
		
		this.imageGraySet();
	}
	
	this.bEnabled = bEnable;
	
}	// buttonEnable

function buttonIsEnabled()
{
	return this.bEnabled;
}	// buttonIsEnabled

function buttonOnMouseOver()
{
	var button = buttonBag[ this.id ];
	if ( button )
	{
		button.imageHotSet();
	
		if ( button.fxMouseOver )
			button.fxMouseOver();
	}
	
}	// buttonOnMouseOver

function buttonOnMouseOut()
{
	var button = buttonBag[ this.id ];
	if ( button )
	{
		button.imageNormalSet();
	
		if ( button.fxMouseOut )
			button.fxMouseOut();
	}
		
}	// buttonOnMouseOut

function buttonOnMouseUp()
{
	var button = buttonBag[ this.id ];
	if ( button )
	{
		button.imageHotSet();
	
		if ( button.fxMouseUp )
			button.fxMouseUp();
	}
		
}	// buttonOnMouseUp

function buttonOnMouseDown()
{
	var button = buttonBag[ this.id ];
	if ( button )
	{
		button.imagePushSet();
	
		if ( button.fxMouseDown )
			button.fxMouseDown();
	}
		
}	// buttonOnMouseDown

function buttonNormal()
{
	if ( !this.imgNormal ) return;
	
	// Set the state of the button to NORMAL. The normal state indicates
	// the button is enabled but does not have any type of focus. This
	// state should be used when the mouse cursor is not over the button
	// and the button does not have the keyboard focus.
	var image = self.document.images[ this.sID ];
	if ( image && image.tagName == "IMG" )
	{
		image.src = this.imgNormal.src;
	}
}	// buttonNormal

function buttonHot()
{
	if ( !this.imgHot ) return;
	
	// Set the state of the button to HOT. The hot state indicates
	// the button is able to be pressed. This state should be used
	// when the mouse cursor is over the button or the button has
	// the keyboard focus.
	var image = self.document.images[ this.sID ];
	if ( image && image.tagName == "IMG" )
	{
		image.src = this.imgHot.src;
	}
}	// buttonHot

function buttonPush()
{
	if ( !this.imgPush ) return;
	
	// Set the state of the button to PUSH. The push state indicates
	// the button has been pressed and has not been released. This state
	// should be used in response to an 'onmousedown' or 'onkeypress' event.
	var image = self.document.images[ this.sID ];
	if ( image && image.tagName == "IMG" )
	{
		image.src = this.imgPush.src;
	}
}	// buttonPush

function buttonGray()
{
	if ( !this.imgGray ) return;
	
	// Set the state of the button to GRAY. The gray state indicates
	// the button is disabled.
	var image = self.document.images[ this.sID ];
	if ( image && image.tagName == "IMG" )
	{
		image.src = this.imgGray.src;
	}
}	// buttonGray
