//------------------------------------------------------------------------
// Name: LW_Structure_Color
// Desc: Stores a color.
//------------------------------------------------------------------------
function LW_Structure_Color()
{

	// What type of argument was passed in?
	if ( arguments.length == 1 && (typeof arguments[0] == "string" || arguments[0] instanceof String) )
	{

		this.R = parseInt( arguments[0].substring( 0, 2 ), 16 );
		this.G = parseInt( arguments[0].substring( 2, 4 ), 16 );
		this.B = parseInt( arguments[0].substring( 4, 6 ), 16 );

	}  // End if hex string.
	else if ( arguments.length == 3 )
	{

		this.R = arguments[0];
		this.G = arguments[1];
		this.B = arguments[2];

	}  // End if numbers passed in.
	else
	{

		this.R = null;
		this.G = null;
		this.B = null;

	}  // End if null passed in.

}

//------------------------------------------------------------------------
// Structure_Color Functions
//------------------------------------------------------------------------
///////////////////////////////////////////
// Returns color as a hex string.
LW_Structure_Color.prototype.toHexString = function()
{

	var R = (this.R < 16) ? "0" + this.R.toString( 16 ) : this.R.toString( 16 );
	var G = (this.G < 16) ? "0" + this.G.toString( 16 ) : this.G.toString( 16 );
	var B = (this.B < 16) ? "0" + this.B.toString( 16 ) : this.B.toString( 16 );

	return R + G + B;

}


//------------------------------------------------------------------------
// Name: LW_Structure_Dimensions
// Desc: Stores the dimensions of something.
//------------------------------------------------------------------------
function LW_Structure_Dimensions( width, height )
{

	// Store the passed in parameters.
	this.width   = width;
	this.height  = height;

}


//------------------------------------------------------------------------
// Name: LW_Structure_Position
// Desc: Stores the position of something.
//------------------------------------------------------------------------
function LW_Structure_Position( top, right, bottom, left )
{

	// Store the passed in parameters.
	this.top     = top;
	this.right   = right;
	this.bottom  = bottom;
	this.left    = left;

}


//------------------------------------------------------------------------
// Name: LW_Structure_Align
// Desc: Used to store horizontal and vertical alignments.
//------------------------------------------------------------------------
function LW_Structure_Align( halign, valign )
{

	// Store the passed in parameters.
	this.halign = halign;
	this.valign = valign;

}


//------------------------------------------------------------------------
// Name: LW_Structure_Point
// Desc: Stores a point.
//------------------------------------------------------------------------
function LW_Structure_Point( X, Y )
{

	// Store the passed in parameters.
	this.X = X;
	this.Y = Y;

}


//------------------------------------------------------------------------
// Name: LW_Structure_Region
// Desc: Stores a region.
//------------------------------------------------------------------------
function LW_Structure_Region()
{

	// What was passed in?
	if ( arguments.length == 2 )
	{

		// Store the passed in parameters.
	  this.min_point  = arguments[0];
	  this.max_point  = arguments[1];

	}  // End if points passed in.
	else if ( arguments.length == 1 )
	{

		var element = arguments[0];

		// Get the element's position for the region's min point.
		this.min_point = LW_DOM_Library.getXY( element );

		// Get the max point for the region.
		this.max_point = new LW_Structure_Point( (this.min_point.X + element.offsetWidth), (this.min_point.Y + element.offsetHeight) );

	}  // End if HTML element passed in.

}

//------------------------------------------------------------------------
// LW_Structure_Region Functions
//------------------------------------------------------------------------
///////////////////////////////////////////
// Returns true if the region is touching the region passed in.
// If in_test is true, then it will will return whether it is fully contained.
LW_Structure_Region.prototype.intersectRegion = function( region, in_test, epsilon )
{

	// Get the epsilon.
	epsilon = (epsilon) ? epsilon : 0;

	// Only do this if we are testing if it's completely contained.
	if ( in_test )
	{

	  var contained = true;

		// Is the region completely contained in this region?
		if ( region.min_point.X < (this.min_point.X + epsilon) || region.min_point.X > (this.max_point.X + epsilon) ) contained = false;
		else if ( region.min_point.Y < (this.min_point.Y + epsilon) || region.min_point.Y > (this.max_point.Y + epsilon) ) contained = false;
		else if ( region.max_point.X < (this.min_point.X + epsilon) || region.max_point.X > (this.max_point.X + epsilon) ) contained = false;
		else if ( region.max_point.Y < (this.min_point.Y + epsilon) || region.max_point.Y > (this.max_point.Y + epsilon) ) contained = false;

		// Return.
		return contained;

	}  // End if completely contained test.
	else
	{

		// Perform the intersection test.
		return ((this.min_point.X + epsilon) <= region.max_point.X) &&
						((this.min_point.Y + epsilon) <= region.max_point.Y) &&
						((this.max_point.X + epsilon) >= region.min_point.X) &&
						((this.max_point.Y + epsilon) >= region.min_point.Y);

	}  // End normal touching test.

}

///////////////////////////////////////////
// Returns true if the region contains the point passed in.
LW_Structure_Region.prototype.containsPoint = function( point )
{

	var contained = true;

	// Is the point completely contained in this region?
	if ( this.min_point.X > point.X || this.max_point.X < point.X ) contained = false;
	if ( this.min_point.Y > point.Y || this.max_point.Y < point.Y ) contained = false;

	// Return.
	return contained;

}


