// VARIABLEN
var mousedistance = [15,15]; // Vertikaler und horizontaler Abstand vom Mauszeiger
var scrollbarSize = [20,20]; // Höhe des horizontalen und Breite des vertikalen Scrollbalkens
var chaserW;
var chaserH;
var chaserID = 'chaser';

if (document.getElementById || document.all)
document.write('<div id="chaser"></div>');

// NEUEN CHASER ANLEGEN -------------------------------------------------------------------------------------------------------------------
function newelement() {

	if (document.createElement) {

		var el = document.createElement('div');
		el.id = chaserID;

		with(el.style) {
			display = 'none';
			position = 'absolute';
			left = '-1000px';
		}

		document.body.appendChild(el);

	}

}

// MITZUBEWEGENDES OBJEKT ZURÜCKGEBEN -----------------------------------------------------------------------------------------------------
function getchaser (withstyle) {
	if (document.getElementById) {
		if (withstyle) {
			return document.getElementById(chaserID).style;
		} else {
			return document.getElementById(chaserID);
		}
	} else if (document.all) {
		if (withstyle) {
			return document.all.chaserID.style;
		} else {
			return document.all.chaserID;
		}
	}
}

// ERMITTELN DES ROOT-ELEMENTS ------------------------------------------------------------------------------------------------------------
function realroot () {
	return (!window.opera && document.compatMode && document.compatMode!='BackCompat')? document.documentElement : document.body
}


// TOOLTIP ANZEIGEN -----------------------------------------------------------------------------------------------------------------------
function showChaser (html, width, cssClass, ticketinglink) {

	if (cssClass == 'program') {


		var inner_html = '<h3>Klicken Sie jetzt um Karten für diese Vorstellung zu reservieren bzw. zu kaufen.</h3><p><big>';
		inner_html += html;
		inner_html += '</big></p><p><small>Ein neues Fenster wird geöffnet.</small></p>';
		getchaser(0).innerHTML = inner_html;

		/* AJAX ABFRAGE TEMPORÄR ABGESCHALTET (08.07.2009)
		getchaser(0).innerHTML = '<h3><big>Bitte warten &hellip;</big></h3><p>Das Online-Reservierungs-Kontingent wird geprüft.</p>';

		http = getHTTPObject();
		var url = "ajax.get_ticketing_site_html.php?ticketinglink=" + ticketinglink + "&html=" + html;

		http.open("GET", url, true);
		//http.setRequestHeader('Cache-Control', 'no-cache');
		http.onreadystatechange = function() {
  			if(http.readyState == 4){
				getchaser(0).innerHTML = http.responseText;
			}
		}
		http.send(null);
		*/

	} else {

		getchaser(0).innerHTML = html;

	}

	if(!getchaser(0)) newelement();

	getchaser(1).display = 'block';
	getchaser(1).width = width + 'px';
	getchaser(0).className = cssClass;

	document.onmousemove = chaseMouse;

}

// TOOLTIP VERSTECKEN ---------------------------------------------------------------------------------------------------------------------
function hideChaser () {
	getchaser(0).innerHTML = ' ';
	getchaser(1).display = 'none';
	document.onmousemove = '';
	getchaser(1).left = '-1000px';
}

// MAUS-VERFOLGER -------------------------------------------------------------------------------------------------------------------------
function chaseMouse (e) {

	var xcoord = mousedistance[0];
	var ycoord = mousedistance[1];

	var documentW = document.all? realroot().scrollLeft+realroot().clientWidth : pageXOffset + window.innerWidth - scrollbarSize[1];
	var documentH = document.all? Math.min(realroot().scrollHeight, realroot().clientHeight) : Math.min(window.innerHeight - scrollbarSize[0]);

	chaserH = getchaser(0).offsetHeight;
	chaserW = getchaser(0).offsetWidth;

	if (typeof e != 'undefined'){

		if (documentW - e.pageX < chaserW + mousedistance[0]){
			xcoord = e.pageX - xcoord - chaserW; // Auf die linke Seite des Mauszeigers wechseln
		} else {
			xcoord += e.pageX;
		}

		if (documentH - e.pageY < (chaserH + mousedistance[1])){
			ycoord += e.pageY - Math.max(0,(mousedistance[1] + chaserH + e.pageY - documentH - realroot().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != 'undefined'){

		if (documentW - event.clientX < chaserW + mousedistance[0]){
			xcoord = event.clientX + realroot().scrollLeft - xcoord - chaserW; // Auf die linke Seite des Mauszeigers wechseln
		} else {
			xcoord += realroot().scrollLeft + event.clientX;
		}

		if (documentH - event.clientY < (chaserH + mousedistance[1])){
			ycoord += event.clientY + realroot().scrollTop - Math.max(0,(mousedistance[1] + chaserH + event.clientY - documentH));
		} else {
			ycoord += realroot().scrollTop + event.clientY;
		}

	}

	var documentW = document.all? realroot().scrollLeft + realroot().clientWidth : pageXOffset + window.innerWidth - scrollbarSize[0];
	var documentH = document.all? Math.max(realroot().scrollHeight, realroot().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight - scrollbarSize[1]);

	if(ycoord < 0) { ycoord = ycoord*-1; }

	getchaser(1).left = xcoord + 'px'
	getchaser(1).top = ycoord + 'px';

}

function delay (prmSec) {

	prmSec *= 1000;
	var eDate = null;
	var eMsec = 0;
	var sDate = new Date();
	var sMsec = sDate.getTime();

	do {
		eDate = new Date();
		eMsec = eDate.getTime();

	} while ((eMsec - sMsec) < prmSec);

}

// Quelle: http://www.harrymaugans.com/2007/03/18/tutorial-ajax-made-easy & http://www.w3schools.com/XML/xml_http.asp
function getHTTPObject(){

	var xmlhttp;

	/*@cc_on

	@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(E) {
			xmlhttp = false;
		}
	}

	@else
	xmlhttp = false;

	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

		try {
			xmlhttp = new XMLHttpRequest();
		} catch(e) {
			xmlhttp = false;
		}

	}

	return xmlhttp;

}