/*
TimothyHumphrey.WebControls
Copyright (c) 2003 - 2004 Timothy Humphrey

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

//-------------------- thwcHighlightCH_Text --------------------\\
thwcHighlightCH_Text = function() {
	this.base = Handler;
	this.base();
	delete this.base;

	this.BackgroundColor;
	this.Color;
	this.HotBackgroundColor;
	this.HotColor;
	this.HotCssClass;

	this.reHotClass;
}
thwcHighlightCH_Text.prototype = new Handler;
thwcHighlightCH_Text.prototype.constructor = thwcHighlightCH_Text;

thwcHighlightCH_Text.reSpaces = /\s{2,}/g;

thwcHighlightCH_Text.prototype.Load = function() {
	var data = this.Control.Data.thwcHighlightCH_Text;

	this.BackgroundColor = data[0];
	this.Color = data[1];
	this.HotBackgroundColor = data[2];
	this.HotColor = data[3];
	this.HotCssClass = data[4];

	this.reHotClass = this.HotCssClass ? new RegExp("\\b" + this.HotCssClass + "\\b") : null;
}

thwcHighlightCH_Text.prototype.Play = function(initiator, highlighted) {
	var element = this.Control.Element;
	var style = element.style;

	if(highlighted) {
		if(this.HotCssClass && !this.reHotClass.test(element.className))
			element.className += " " + this.HotCssClass;
		style.backgroundColor = this.HotBackgroundColor ? this.HotBackgroundColor : "";
		style.color = this.HotColor ? this.HotColor : "";
	}
	else {
		if(this.HotCssClass)
			element.className = element.className.replace(this.reHotClass, "").replace(thwcHighlightCH_Text.reSpaces, " ");
		style.backgroundColor = this.BackgroundColor ? this.BackgroundColor : "";
		style.color = this.Color ? this.Color : "";
	}
}

