// Object for highlighting dynamically menuentries.
//
// (c) DIG GmbH, 2009
//
// _prefix : prefix for menu entry's id (<prefix><menuentryNo>)
// _length : number of menu entries
// _style : style of a non highlighted menu entry
// _highlightStyle : style of a highlighted menu entry
//
// Note: syntax for styles: <javascript-style-property><'='><value>
//	          multiple styles must be separated by semicolon
function MenuHighlightConfig(_prefix, _length, _style, _highlightStyle) {

	this.menuPrefix = _prefix ? _prefix : "";
	this.menuLength = _length ? _length : 0;
	this.style = _style ? _style : "color=#000000";
	this.highlightStyle = _highlightStyle ? _highlightStyle : "color=#FFFFFF";
}

function MenuChanger(_config, _target_id) {

	this.config = _config ? _config : new MenuHighlightConfig(); // configuration for highlightning
	this.targetId = _target_id ? _target_id : "NO_ID_SET"; // id required for replacements from ajax-request

	this.doHighlightMenuEntry =

	//_entryNo : suffix for menu entry's id
	function(_entryNo) {

		if (_entryNo != null) {

			var elem;
			var style = null;
			var styleNormal = this.config.style.split(";");
			var styleHighlight = this.config.highlightStyle.split(";");
			var keyPair = null;
			for ( var i = 0; i < this.config.menuLength; i++) {

				elem = document.getElementById(this.config.menuPrefix + i);
				if (elem != null) {

					if (_entryNo == i)
						style = styleHighlight;
					else
						style = styleNormal;

					for ( var j = 0; j < style.length; j++) {

						keyPair = style[j].split("=");
						eval("elem.style." + keyPair[0] + "=\"" + keyPair[1]
								+ "\"");
					}
				}
			}
		}
	};

	this.changeMenuEntry =

	// _entryNo : suffix for menu entry's id
	// _url : url used for ajax-request
	function(_entryNo, _url) {

		if (_entryNo != null && _url != null) {

			this.doHighlightMenuEntry(_entryNo);
			refreshInnerHtmlById(_url, this.targetId);
		}
	};
}
