function Blink(Obj) {

	if (!Blink.blink_arr) {
		Blink.blink_arr = new Array();
	}

	Blink.doBlink = function() {

		var Obj = Blink.blink_arr.shift();
		Blink.blink_arr.push(Obj);

		if (!Obj.src) {
			Obj.style.backgroundColor = '#fffaad';
		}
		setTimeout('Blink.undoBlink()', 100);
	}

	Blink.undoBlink = function() {

		var Obj = Blink.blink_arr.shift();

		if (!Obj.src) {
			Obj.style.backgroundColor = '#FFFFFF';
		}
	}

	Blink.blink_arr.push(Obj);
	setTimeout('Blink.doBlink()', 100);
	Blink.blink_arr.push(Obj);
	setTimeout('Blink.doBlink()', 300);
	Blink.blink_arr.push(Obj);
	setTimeout('Blink.doBlink()', 500);
}

function tt_error(Obj, text, headline) {
	if (typeof (Obj) == 'string') {
		Obj = document.getElementById(Obj);
	}
	if (Obj2 = document.getElementById(Obj.attributes.id.value + '_h')) {
		Obj2.style.display = 'none';
	}

	if (!Obj.disabled && Obj.focus) {
		Obj.focus();
	}
	ToolTip.show_input = true;
	if (text && headline) {
		ToolTip.show(Obj, text, headline);
	} else {
		ToolTip.show(Obj, text);
	}
	new Blink(Obj);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function ToolTipClass(isForm) {
	this.isForm = (isForm) ? true : false;

	if (!isForm) {
		this.Obj = document.getElementById('ToolTip');
		this.ObjArr = document.getElementById('ToolTipArrow');
		this.Ifr = document.getElementById('Inline');
		this.TT = 'ToolTip';
		this.yoffset = 40;

	} else {
		this.Obj = document.getElementById('FormToolTip');
		this.ObjArr = document.getElementById('FormToolTipArrow');
		this.Ifr = document.getElementById('FormInline');
		this.TT = 'FToolTip';
	}

	this.drag = false;
	this.offset_x = false;
	this.offset_y = false;
	this.start_x = false;
	this.start_y = false;
	this.speed = 0.2;
	this.go_to_corner = false;
	this.active = true;

	this.yoffset = -5;
	this.xoffset = 1;
	this.show_input = false;
	this.dragPause = false;

	this.hasFinishedMove = false;
	this.shouldFocus = false;
	
	// Muss immer tooltip_arrow.gif im Namen haben und nie 'tooltip_arrow' an anderer Stelle (s. Abfrage unten) 
	this.arrowsrc = '/images/v5/tooltip/tooltip_arrow.gif';
	// Muss immer tooltip_arrow_up. im Namen haben und nie 'tooltip_arrow_up.' an anderer Stelle (s. Abfrage unten) 
	this.arrowupsrc = '/images/v5/tooltip/tooltip_arrow_up.gif';
	
	this.button_x = '/images/v5/tooltip/button_x.gif';

	this.focus = function() {
		this.shouldFocus = true;
	}

	this.finishedMove = function(l, t, w, h) {

		this.hasFinishedMove = true;

		if (this.shouldFocus) {
			this.shouldFocus = false;

			var myWidth = 0, myHeight = 0;
			if (typeof (window.innerWidth) == 'number') {
				// Non-IE
				myWidth = window.innerWidth;
				myHeight = window.innerHeight;
			} else if (document.documentElement
					&& (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
				// IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
			} else if (document.body
					&& (document.body.clientWidth || document.body.clientHeight)) {
				// IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}

			var xo = f_filterResults(
					window.pageXOffset ? window.pageXOffset : 0,
					document.documentElement ? document.documentElement.scrollLeft
							: 0, document.body ? document.body.scrollLeft : 0);// window.pageXOffset
			var yo = f_filterResults(
					window.pageYOffset ? window.pageYOffset : 0,
					document.documentElement ? document.documentElement.scrollTop
							: 0, document.body ? document.body.scrollTop : 0);// window.pageYOffset

			if (l - 25 < xo || t - 25 < yo) {
				// Flüssig zum ToolTip scrollen
				var t_x = l - 25;
				var t_y = t - 25;
			} else if (l + w + 25 > xo + myWidth || t + h + 50 > yo + myHeight) {
				var t_x = l - 25;
				var t_y = t - 25;
			} else {
				return false;
			}

			var s_x = xo;
			var s_y = yo;

			var i = 0;
			var fps = 50;
			var duration = 750 / 2;
			var steps = duration / (1000 / fps);
			var ttscroll = setInterval( function() {
				// var d = Math.sqrt(Math.pow(t_x - s_x, 2) + Math.pow(t_y -
				// s_y, 2));
					var dp = ((Math.cos(Math.PI * ((steps - i) / steps)) + 1) / 2);
					var n_x = s_x + (t_x - s_x) * dp;
					var n_y = s_y + (t_y - s_y) * dp;
					scrollTo(n_x, n_y);

					i++;
					if (i > steps) {
						clearInterval(ttscroll);
					}
				}, 1000 / fps);
		}
	}

	this.endDragPause = function() {
		ToolTip.dragPause = false;
		this.dragPause = false;
	}

	this.reactivate = function() {
		this.active = true;
		this.go_to_corner = false;
		this.show(true, this.target, this.text, this.headline);
	}

	this.hide = function() {
		this.Obj.innerHTML = '';
		this.Obj.style.display = 'none';
		this.ObjArr.style.display = 'none';
		this.Ifr.style.display = "none";
	}

	this.show = function(target, text, headline) {

		
		if (typeof (target) == 'boolean') {
			this.hide();
			return false;
		} else if (typeof (target) == 'string') {
			target = document.getElementById(target);
			
		}
		
		if (!this.Obj) {
			this.Obj = document.getElementById(this.TT);
		}
		
		if (this.isForm){
			this.showAt('mouse', text, headline)
			return false;
		}
		
		this.hasFinishedMove = false;

		if (this.show_input && target.type != 'checkbox') {
			this.xoffset = 1;
			this.yoffset = -24;
		} else {
			this.xoffset = 1;
			this.yoffset = -6;
		}

		this.show_input = false;
		this.Obj.style.display = 'block';

		this.target = target;

		this.text = text;
		this.headline = headline;

		if (!this.active)
			return false;

		if (this.go_to_corner) {
			this.toTop();
		} else {
			this.toBox();
		}

		if (this.target) {
			clearInterval(this.Intv);
			this.Intv = setInterval('ToolTip.follow()', 10);
			
		} else {
			this.Obj.style.display = 'block';
			this.Ifr.style.zIndex = this.Obj.style.zIndex - 1;
			this.Ifr.style.display = "block";
			this.left = m_x + 10;
			this.top = m_y + 15;
			this.Obj.style.left = this.left + 'px';
			this.Obj.style.top = this.top + 'px';
			this.ObjArr.style.display = "none";
			
			// this.Ifr.style.top = this.Obj.style.top;
			// this.Ifr.style.left = this.Obj.style.left;
			// this.Ifr.style.width = this.Obj.offsetWidth;
			// this.Ifr.style.height = this.Obj.offsetHeight;
		}
	}

	this.toTop = function() {
		this.go_to_corner = true;

		this.ObjArr.style.display = 'none';
		this.Obj.style.cursor = "auto";

		this.left = 0;
		this.top = 0;

		if (this.headline) {
			this.Obj.innerHTML = '<div class="ttshadow5"><div class="ttshadow4"><div class="ttshadow3"><div class="ttshadow2"><div class="ttshadow">'
					+ '<table cellspacing="0" class="null" width="100%"><tr><td valign="top" style="padding-right: 3px; padding-top: 2px; padding-bottom: 2px; border-right: 1px solid #B7B791;"><b>'
					+ this.headline
					+ '</b></td><td valign="top" style="padding: 3px;">'
					+ this.text
					+ '</td><td valign="top" align="right"><a href="javascript:void '
					+ this.TT
					+ '.toBox();" title="Direkte Kontexthilfe"><img src="/images/v5/tooltip/button_down.gif" width="16" height="16"></a><a href="javascript:void '
					+ this.TT
					+ '.show(false);" title="Deaktiviere Kontexthilfe"><img src="'+this.button_x+'"></a></td></tr></table>'
					+ '</div></div></div></div></div>';
		} else {
			this.Obj.innerHTML = '<table cellspacing="0" class="null" width="100%"><tr><td valign="top" style="padding: 3px;">'
					+ this.text
					+ '</td><td valign="top" align="right"><a href="javascript:void '
					+ this.TT
					+ '.toBox();" title="Direkte Kontexthilfe"><img src="/images/v5/tooltip/button_down.gif" width="16" height="16"></a><a href="javascript:void '
					+ this.TT
					+ '.show(false);" title="Deaktiviere Kontexthilfe"><img src="'+this.button_x+'"></a></td></tr></table>';
		}

		return false;
	}

	this.click = function() {
		
	}

	this.toBox = function() {
		this.go_to_corner = false;

		if (this.lastTarget && this.target == false) {
			this.target = this.lastTarget;
		}
		if (this.headline) {
			this.Obj.innerHTML = '<div class="ttshadow5"><div class="ttshadow4"><div class="ttshadow3"><div class="ttshadow2"><div class="ttshadow">'
					+ '<table cellspacing="0" class="null"><tr><td style="padding-left: 4px;padding-right: 3px; padding-top: 2px; padding-bottom: 2px; border-bottom: 1px solid #B7B791;"><b>'
					+ this.headline
					+ '</b></td><td valign="top" align="right" style="border-bottom: 1px solid #B7B791;"><a id="tt_a_close" href="javascript:void '
					+ this.TT
					+ '.show(false);" title="Schlie&szlig;en"><img src="'+this.button_x+'"></a></td></tr><tr><td valign="middle" style="padding: 3px;" colspan="2">'
					+ this.text
					+ '</td></table>'
					+ '</div></div></div></div></div>';
		} else {
			this.Obj.innerHTML = '<table cellspacing="0" class="null"><tr><td valign="middle" style="padding-left: 4px; padding-right: 3px;">'
					+ this.text
					+ '</td><td valign="top"><a id="tt_a_close" href="javascript:void '
					+ this.TT
					+ '.show(false);" title="Schlie&szlig;en"><img src="'+this.button_x+'"></a></td></tr></table>';
		}

		if (!this.ObjArr) {
			this.ObjArr = document.getElementById(this.TT + 'Arrow');
		}
		this.ObjArr.style.display = 'block';
		this.ObjArr.innerHTML = '<img src="'+this.arrowsrc+'">';

		if (!this.Ifr) {
			this.Ifr = document.getElementById('Inline');
		}

		this.Ifr.style.zIndex = this.Obj.style.zIndex - 1;
		this.Ifr.style.display = "block";
	}
	this.showAt = function(target,text,headline,x,y) {
		this.hide();
		this.headline = headline;
		this.text = text;
		this.toBox();
		this.Obj.style.display='block';
		this.ObjArr.style.display = 'none';
		if(target == 'mouse') {
			this.target = null;
			x = null;y=null;
		}
		this.moveTo(x,y);
	}

	this.moveTo = function(left,top) {
		
		ow = xWidth(this.Obj);
		xo = Math.round((1000-ow)/2)-10;
		y = (top)?top:m_y;
		y += 15;
		x = (left)?top:xo;
		new Effect.Move(this.Obj,{ x: x, y: y, mode: "absolute", duration: 0.8});
		new Effect.ScrollTo(this.Obj.id,{delay:0.9});
		return true;

	}
	this.follow = function() {
		if (!this.Intv)
			return false;
		
		Obj_left = Number(this.Obj.style.left.substr(0, this.Obj.style.left
				.lastIndexOf("p")));
		Obj_top = Number(this.Obj.style.top.substr(0, this.Obj.style.top
				.lastIndexOf("p")));

		this.tempLeft = Obj_left;
		this.tempTop = Obj_top;
		if (this.go_to_corner != false || this.dragPause) { //

		} else if (this.drag) {
			this.top = m_y + this.offset_y;
			this.left = m_x + this.offset_x;
		} else {
			if (!this.target) {
				return false;
			}

			var t = this.target;

			try {
				if (t.offsetParent) {
					this.t_left = 0;
					while (t.offsetParent) {
						this.t_left += t.offsetLeft
						t = t.offsetParent;
					}
				} else if (t.x) {
					this.t_left += t.x;
				}

				var t = this.target;

				if (t.offsetParent) {
					this.t_top = 0;
					while (t.offsetParent) {
						this.t_top += t.offsetTop
						t = t.offsetParent;
					}
				} else if (t.y) {
					this.t_top += t.y;
				}
			} catch (e) {
				// ie 7 bug: kann auf t.offsetParent nicht zugreifen?
			}

			imgsrc = this.ObjArr.getElementsByTagName('img')[0].src;

			/*
			 * Wir kommen hier an einen Punkt mit ernsthaften Problemen. Derzeit
			 * wird überprüft ob unser ToolTip rechts(!) genug Platz zum
			 * zeichnen hat. Das führt fast zwangsläufig zu einem Problem, da
			 * nicht gesagt ist das links genug Platz ist. Das Problem gilt
			 * analog auch für die vertikale Aurichtung, auch wenn das Problem
			 * hier lange nicht so schwerwiegend ist. Das Ergebnis dieser sehr
			 * vereinfachten Berechnung ist, dass der Tooltip unter Umständen
			 * links aus dem Bild verschwindet!
			 */

			/*
			 * Possible options: < 0 ::= the new position will be below the
			 * destination object = 0 ::= the new position will be above the
			 * destination object > 0 ::= the new position will be above the
			 * destination object
			 */
			var drawPositionVertical = (this.t_top - xHeight(this.Obj));

			var drawSpaceLeft = this.t_left;
			var drawSpaceRight = xWidth(document.body)
					- (this.t_left + xWidth(this.Obj));

			// alert( "Space-Left: " + drawSpaceLeft );
			// alert( "Space-Right: " + drawSpaceRight );

			if (this.t_top < xHeight(this.Obj)) {
				this.t_top = this.t_top
						+ (xHeight(this.Obj) + xHeight(this.target) + 15);
				draw_below = true;
			} else {
				draw_below = false;
			}

			if (this.t_left + xWidth(this.Obj) > xWidth(document.body)) {
				this.t_left = this.t_left - xWidth(this.Obj)
						+ xWidth(this.target);
				draw_right = true;
			} else {
				draw_right = false;
			}

			this.left = Math.round(Obj_left
					+ (this.t_left - Obj_left + this.xoffset) * this.speed);
			this.top = Math
					.round(Obj_top
							+ (this.t_top - this.Obj.offsetHeight
									+ this.yoffset - Obj_top) * this.speed);

			if (draw_below) {
				this.ObjArr.style.top = (this.top - 8) + 'px';

				if (imgsrc.substr(imgsrc.indexOf("tooltip_arrow"), 17) != 'tooltip_arrow_up.') {
					this.ObjArr.innerHTML = '<img src="'+this.arrowupsrc+'">';
				}
			} else {
				this.ObjArr.style.top = (this.top + this.Obj.offsetHeight - 1) + 'px';

				if (imgsrc.substr(imgsrc.indexOf("tooltip_arrow"), 17) != 'tooltip_arrow.gif') {
					this.ObjArr.innerHTML = '<img src="'+this.arrowsrc+'">';
				}
			}
			if (draw_right) {
				// this.ObjArr.style.left = (this.left + 608) + 'px';
				this.ObjArr.style.left = (xLeft(this.Obj) + xWidth(this.Obj) - 18) + 'px';

			}

		}

		this.Obj.style.left = this.left + 'px';
		this.Obj.style.top = this.top + 'px';

		this.Ifr.style.top = this.Obj.style.top;
		this.Ifr.style.left = this.Obj.style.left;

		if (this.hasFinishedMove == false
				&& Math.abs(this.t_left - this.left + this.xoffset) < 5
				&& Math.abs(this.t_top - this.Obj.offsetHeight + this.yoffset
						- this.top) < 5) {
			this.finishedMove(this.left, this.top, this.Obj.offsetWidth,
					this.Obj.offsetHeight);
		}

		if (draw_right) {
			this.ObjArr.style.left = (xLeft(this.Obj) + xWidth(this.Obj) - 18) + 'px';

		} else {
			this.ObjArr.style.left = (this.left + 5) + 'px';
		}

	}
}

function getMouseXY(e) {
	if (document.all) {
		event.cancelBubble = true;
		m_x = event.clientX + document.body.scrollLeft
		m_y = event.clientY + document.body.scrollTop
	} else {
		m_x = e.pageX;
		m_y = e.pageY;
	}
}
if(!ToolTip){
	var ToolTip = new ToolTipClass();
	var FToolTip = new ToolTipClass(1);
	m_x = 0;
	m_y = 0;
	document.onmousemove = getMouseXY;
}

