//-------------------------------------------------------------------------------
// Object: ImageTab
//
// Parameters:
//		image - A reference to an html image <img> object.
//
// Description:
//
// The ImageTab object provides commonly used image functionality. It adds 
// mouseover functionality and a click event that can be propagated to the 
// caller. 
//-------------------------------------------------------------------------------
function ImageTab(name, image) 
{
	// init vars
	var _Active = false;
	var _Height = null;
	var _Image = image;
	var _Name = name;
	var _Off = null;
	var _Over = null;
	var _On = null;
	var _This = this;
	var _Width = null;
	
	// get the height and width of the image tab
	_Height = image.height;
	_Width = image.width;
	
	// create the off object based on the supplied image
	_Off = new Image(_Width, _Height);
	_Off.src = image.src;
	
	//--------------------------------------------
	// Get the underlying html image <img> object.
	//--------------------------------------------
	function getImage() 
	{
		return _Image;
	}
	
	this.getImage = getImage;
	
	//--------------------------
	// Gets the name of the tab.
	//--------------------------
	function getName() 
	{
		return _Name;
	}
	
	this.getName = getName;
	
	//----------------------------------------------
	// Indicates whether or not the button is active
	//----------------------------------------------
	function isActive() 
	{
		return _Active;
	}
	
	this.isActive = isActive();
	
	//--------------------------------------------------------------------
	// Handles onmouseout event. Sets the ImageButton back to its original
	// state unless it is active.
	//--------------------------------------------------------------------
	function onMouseOut() 
	{
		// only swap images when not active
		if (_Active == false) {
			_Image.src = _Off.src;
		}
	}
	
	_Image.onmouseout = onMouseOut;
	
	//------------------------------------------------------------------
	// Handles onmouseover event. Sets the ImageButton to its over state
	// unless the ImageButton is active.
	//------------------------------------------------------------------
	function onMouseOver() 
	{
		// only swap images when not active
		if (_Active == false && _Over != null) {
			_Image.src = _Over.src;
		}
	}
	
	_Image.onmouseover = onMouseOver;

	//----------------------------------------------------------------------
	// Set the image that should be displayed when a mouseover event occurs.
	//
	// Parameters;
	//		src - the relative path to the over image.
	//----------------------------------------------------------------------
	function setOver(src) 
	{
		_Over = new Image(_Width, _Height);
		_Over.src = src;
	}
	
	this.setOver = setOver;
	
	//------------------------------------------------------------------
	// Set the image that should be displayed when a click event occurs.
	//
	// Parameters;
	//		src - the relative path to the on image.
	//------------------------------------------------------------------
	function setOn(src) 
	{
		_On = new Image(_Width, _Height);
		_On.src = src;
	}
	
	this.setOn = setOn;
	
	//---------------------------------------------------------------
	// Activates the tab. Sets the tab to its "On" state and disables
	// mouseovers.
	//---------------------------------------------------------------
	function activate() 
	{
		// only swap images when not active
		if (_Active == false && _On != null) {
			// set tab selected image
			_Image.src = _On.src;
			
			// mark as active
			_Active = true;
		}
	}
	
	this.activate = activate;
	
}