var loadedGlossaryId = 0;
/**
 * Glossar Hint Klasse
 *
 * @version 1.0
 * @access  public
 */
function glossaryHint() {
	this.divelement = document.getElementById("showHint");
	this.divshadowelement = document.getElementById("showHintShadow");
	this.hints = new Array();

	this.init = function() {
		if (!document.all) {
			// window.captureEvents(Event.MOUSEMOVE | Event.MOUSEOVER);
			onmousemove = mouseMove;
			onmouseover = mouseOver;
		} else {
			with (document) {
				onmousemove = mouseMove;
				onmouseover = mouseOver;
			}
		}
	}

	this.getHintById = function(id) {
		for ( var i = 0; i < this.hints.length; i++) {
			if (this.hints[i]['idx'] == id) {
				return this.hints[i];
			}
		}
		return false;
	}

	this.deactivate = function() {
		var mySpans = getElementsByClassName(document.getElementById("strategy_content"), "a", "glossaryHint");
		for ( var i = 0; i < mySpans.length; i++) {
			mySpans[i].className = "glossaryHintDeactivated";
		}

		document.getElementById("deactivateHints").style.display = "none";
		document.getElementById("activateHints").style.display = "block";
	}

	this.activate = function() {
		var mySpans = getElementsByClassName(document.getElementById("strategy_content"), "a", "glossaryHintDeactivated");
		for ( var i = 0; i < mySpans.length; i++) {
			mySpans[i].className = "glossaryHint";
		}

		document.getElementById("deactivateHints").style.display = "block";
		document.getElementById("activateHints").style.display = "none";
	}

	/**
	 * Event Target bekommen
	 *
	 * @version 1.0
	 * @access  private
	 * @param   Event ev
	 * @return  HTML Object Element
	 */
	var getTarget = function(ev) {
		if (!document.all) {
			return ev.target;
		} else {
			return window.event.srcElement;
		}
	}

	/**
	 * Switcher für MouseOver Events
	 *
	 * @version 1.0
	 * @access  private
	 * @param   Event ev
	 * @return  void
	 */
	var mouseOver = function(ev) {
		var thisTarget = getTarget(ev);
		mouseMove(ev);
		if (thisTarget.className == "glossaryHint") {
			var hintId = new String(thisTarget.getAttribute('id'));
			hintId = hintId.replace("glossary_", "");
			if (hintId != loadedGlossaryId) {
				var cachedHint = myG.getHintById(hintId);
				if (!cachedHint) {
					getGlossary(hintId);
					myG.divelement.innerHTML = "loading...";
				} else {
					myG.showResult(cachedHint);
				}

				loadedGlossaryId = hintId;
			} else {
				myG.divelement.style.display = "block";
				myG.divshadowelement.style.display = "block";
			}
		} else {
			myG.divelement.style.display = "none";
			myG.divshadowelement.style.display = "none";
		}
	}

	var mouseMove = function(ev) {
		getMouseCoords(ev);
		xMouse -= (myG.divelement.offsetWidth / 2);
		yMouse += 20;
		myG.divelement.style.left = xMouse + "px";
		myG.divelement.style.top = yMouse + "px";
		myG.divshadowelement.style.left = xMouse + 3 + "px";
		myG.divshadowelement.style.top = yMouse + 3 + "px";
		var newHeight = myG.divelement.offsetHeight;
		var newWidth = myG.divelement.offsetWidth;
		myG.divshadowelement.style.height = newHeight + "px";
		myG.divshadowelement.style.width = newWidth + "px";
	}

	this.showResult = function(result) {
		if (!this.getHintById(result['idx'])) {
			this.hints.push(result);
		}
		var formatted = "<b>" + result['title'] + "</b><hr />" + result['body'];
		this.displayResult(formatted);
	}

	this.displayResult = function(result) {
		this.divelement.innerHTML = result;

		var newHeight = this.divelement.offsetHeight;
		var newWidth = this.divelement.offsetWidth;

		this.divshadowelement.style.height = newHeight + "px";
		this.divshadowelement.style.width = newWidth + "px";
		this.divelement.style.display = "block";
		this.divshadowelement.style.display = "block";
	}
}