var USSuggest = function (input, container, arrayStyle) {
	this.elementInput = typeof input == "string" ? document.getElementById(input) : input;
	this.elementContainer = typeof input == "string" ? document.getElementById(container) : input;
	this.stringValue = this.elementInput.value == "" ? " " : this.elementInput.value;
	this.arrayStyle = arrayStyle;
	this.stringTitles = "";
	this.arrayA = [];
	this.arrayMatched = [];
	this.threadScan = -1;
	this.stringLastValue = "";
	
	this.scan = function () {
		if (arguments.callee._this.elementInput.value == arguments.callee._this.stringLastValue) return;
		var _this = arguments.callee._this;
		var arrayMatchedTemp = [];
		var stringIndexAll = ",";
		if (_this.elementInput.value != "") {
			var arrayMatchString = _this.stringTitles.match(new RegExp("<[^>]*," + _this.elementInput.value + "[^,]*,[^>]*>", "ig"));
			if (arrayMatchString != null) {
				for (var i = 0; i < arrayMatchString.length; i++) {
					var stringIndex = arrayMatchString[i].match(/\d{1,}/)[0];
					stringIndexAll += stringIndex + ",";
					arrayMatchedTemp.push(_this.arrayA[stringIndex]);
				}
			}
		}
		for (var i = 0; i < _this.arrayMatched.length; i++) {
			if (stringIndexAll.indexOf("," + _this.arrayMatched[i].stringIndex + ",") == -1) {
				_this.arrayMatched[i].className = _this.arrayStyle[0];
			}
		}
		for (var i = 0; i < arrayMatchedTemp.length; i++) {
			arrayMatchedTemp[i].className = _this.arrayStyle[("," + arrayMatchedTemp[i].title + ",").match(new RegExp("," + _this.elementInput.value + ",", "ig")) != null ? 2 : 1];
		}
		_this.arrayMatched = arrayMatchedTemp;
		_this.stringLastValue = _this.elementInput.value;
	};
	this.scan._this = this;
	
	var arrayAllA = document.getElementsByTagName("A");
	var count = 0;
	for (var i = 0; i < arrayAllA.length; i++) {
		if (arrayAllA[i].rel == "suggest") {
			this.arrayA.push(arrayAllA[i]);
			arrayAllA[i].stringIndex = count;
			this.stringTitles += "<" + count + "|," + arrayAllA[i].title + ",>";
			count++;
		}
	}
	
	elementInput = this.elementInput;
	elementInput._this = this;
	elementInput.autocomplete = "off";
	elementInput.onfocus = function () {
		var _this = this._this;
		if (typeof _this.arrayStyle[3] == "string") _this.elementContainer.className = _this.arrayStyle[3]; else _this.arrayStyle[3]();
		this.value = this.value == _this.stringValue ? "" : this.value;
		_this.threadScan = setInterval(_this.scan, 10);
	};
	elementInput.onblur = function () {
		var _this = this._this;
		if (typeof _this.arrayStyle[4] == "string") _this.elementContainer.className = _this.arrayStyle[4]; else _this.arrayStyle[4]();
		this.value = this.value == "" ? _this.stringValue : this.value;
		if (_this.threadScan != -1) {
			clearInterval(_this.threadScan);
			_this.threadScan = -1;
		}
	};
}
