/** overlay info -- show the information for  toolbuttons
*  Creates a http request object for ajax interface to defininition of information
*  from a php file. Makes a div to information show
*  insert in index (important! after <body>-tag for Safari-conpatibility):
*    var akaInfo = new aka_overlay(PHP file get Ajax variables);
*  to use: 			akaInfo.show(key); akaInfo.hide();
*  
*  @author Andrey Karachev <a.karachev@baum-systems.de>
*
*/
aka_x = 0;
aka_y = 0;

aka_all = new Object();
http_overlay = createRequestObject();

function aka_overlay(file) {
	this.show = aka_show;
	this.hide = aka_hide;
	this.tshow = aka_show_text;
	this.space_x = 10;
	this.space_y = 10;
	this.show_time = 2000;
	document.onmousemove = aka_position;
	
	this.error_text = 'The information for "%key%" doesn\'t exist!';
	aka_all['test'] = 'It is a test for the overlay';
	aka_all['aka_error'] = this.error_text;
	
	http_overlay.open('get', file);
	http_overlay.onreadystatechange = function () {
		if((http_overlay.readyState == 4) && (http_overlay.status == 200)) {
			var response = http_overlay.responseText;
			//alert(response);
			if(response.indexOf('|') != -1) {
				var update = new Array();
				update = response.split('|');
				for(i = 0; i < update.length; i+=2) {
					if(update[i + 1] || update[i + 1] == "") {
						aka_all[update[i]] = update[i + 1];
					}
				}
			}
		}
	};
	http_overlay.send(null);
	
	aka_area =	'<div id="aka_info" style="position:absolute;top:0px;left:0px;padding:2px;background-color:#FFFFCC;color:#000;display:none;text-align:center;white-space:nowrap;z-index:99;"></div>';
	
	document.write(aka_area);
}
function createRequestObject() {
	var ro;   
	if(navigator.appName.search("Microsoft") > -1) {
		if(ro = new ActiveXObject("Microsoft.XMLHTTP"));
		else if (ro = new ActiveXObject("MSXML2.XMLHTTP"));
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}
function aka_position(e) {
	if(!e) e = window.event || arguments.callee.caller.arguments[0];
	if(document.all) {
		aka_x = e.clientX;
		aka_y = e.clientY;
	} else if(document.getElementById) {
		aka_x = e.pageX;
		aka_y = e.pageY;
	}
}
function aka_win_width () {
	if (window.innerWidth) {
   		return window.innerWidth;
	} else if(document.documentElement.offsetWidth) {
		return document.documentElement.offsetWidth;
	} else if (document.body && document.body.offsetWidth) {
   		return document.body.offsetWidth;
	} else {
   		return 0;
	}
}
function aka_win_height () {
	if (window.innerHeight) {
  		return window.innerHeight;
	} else if(document.documentElement.offsetHeight) {
		return document.documentElement.offsetHeight;
	} else if (document.body && document.body.offsetHeight) {
		return document.body.offsetHeight;
	} else {
  		return 0;
	}
}
function aka_show(id) {
	document.onmousemove = aka_position;
	document.onmouseover = aka_position;
	info = "";
	if(aka_all[id])
		info = aka_all[id];
	else
		info = this.error_text.replace(/%key%/, id);
	l = info.length * 6.8 + this.space_x;
	h = 30 + this.space_y;
	win_width = window.pageXOffset + window.innerWidth;
	win_height = window.pageYOffset + window.innerHeight;
	x = aka_x + this.space_x;
	y = aka_y + this.space_y;
	if(x > (win_width - l))
		x -= l;
	if(y > (win_height - h))
		y -= h;
	
	document.getElementById('aka_info').style.left = x + "px";
	document.getElementById('aka_info').style.top = y + "px";
	document.getElementById('aka_info').innerHTML = info;
	document.getElementById('aka_info').style.display = "block";
	
	aktiv = window.setTimeout("aka_hide()", this.show_time);
}
function aka_show_text(info) {
	document.onmousemove = aka_position;
	document.onmouseover = aka_position;
	l = info.length * 6.8 + this.space_x;
	h = 30 + this.space_y;
	win_width = window.pageXOffset + window.innerWidth;
	win_height = window.pageYOffset + window.innerHeight;
	x = aka_x + this.space_x;
	y = aka_y + this.space_y;
	if(x > (win_width - l))
		x -= l;
	if(y > (win_height - h))
		y -= h;
	
	document.getElementById('aka_info').style.left = x + "px";
	document.getElementById('aka_info').style.top = y + "px";
	document.getElementById('aka_info').innerHTML = info;
	document.getElementById('aka_info').style.display = "block";
	
	aktiv = window.setTimeout("aka_hide()", this.show_time);
}
function aka_hide() {
	document.onmousemove = aka_position;
	window.clearTimeout(aktiv);
	document.getElementById('aka_info').style.display = "none";
	document.getElementById('aka_info').innerHTML = "";
}