﻿window.onload = function(e) 
{
  if(document.createElement) tooltip.d();
}

tooltip = {

	t: document.createElement("div"),
	c: null,
	g: false,
  
	m: function(e)
	{
    	if(tooltip.g)
		{
			x = window.event ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			y = window.event ? event.clientY + document.documentElement.scrollTop  : e.pageY;
	  
			var window_height = (document.all) ? document.documentElement.clientHeight : window.innerHeight;
			
			if (y > (((window_height+document.documentElement.scrollTop)/4)*3)) y = y-170;
			
			tooltip.a(x,y);
		}
	},

	d: function() 
	{
		tooltip.t.setAttribute("id","tooltipp_geotope");
		document.body.appendChild(tooltip.t);
		
		a = document.getElementById("geotopkarte").getElementsByTagName("area");
		
		for(var i=0; i<a.length; i++) 
		{
			if(a[i].getAttribute("title")) 
			{
				a[i].setAttribute("text",a[i].getAttribute("title"));
				a[i].removeAttribute("title");
				a[i].removeAttribute("alt");
				//if(a[i].getAttribute("alt") && a[i].complete) a[i].removeAttribute("alt");
				
				tooltip.l(a[i],"mouseover",tooltip.s);
				tooltip.l(a[i],"mouseout",tooltip.h);
			} 
			else if(a[i].getAttribute("alt") && a[i].complete) 
			{
				a[i].setAttribute("text",a[i].getAttribute("alt"));
				a[i].removeAttribute("alt");
				
				tooltip.l(a[i],"mouseover",tooltip.s);
				tooltip.l(a[i],"mouseout",tooltip.h);
			}
		}
		document.onmousemove = tooltip.m;
	},

	s: function(e) 
	{
	    d = (window.event) ? window.event.srcElement : e.currentTarget;
		
		var tooltipp_nr = d.getAttribute("text").substring(4,d.getAttribute("text").indexOf(":"));
		var tooltipp_text = d.getAttribute("text");
		var tooltipp_head = document.createElement("h1");
		tooltipp_head.appendChild(document.createTextNode(tooltipp_text));
		var tooltipp_img = document.createElement("img");
		tooltipp_img.width = 170;
		tooltipp_img.height = 128;
		tooltipp_img.src = "pic/mouseover/"+tooltipp_nr+".jpg";
		
		tooltip.t.appendChild(tooltipp_head);
		tooltip.t.appendChild(tooltipp_img);
		
		tooltip.c = setTimeout("tooltip.t.style.visibility = \'visible\';",50);
		tooltip.g = true;
	},

	h: function(e) 
	{
		tooltip.t.style.visibility = "hidden";
		if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
		if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
		clearTimeout(tooltip.c);
		tooltip.g = false;
		
		tooltip.a(-299,-299);
	},
	
	l: function(o,e,a) 
	{
		if(o.addEventListener) o.addEventListener(e,a,true);
		else if(o.attachEvent) o.attachEvent("on"+e,a);
		else return null;
	},
	
	a: function(x,y) 
	{
		tooltip.t.style.left = x + 8 + "px";
		tooltip.t.style.top  = y + 8 + "px";
	}

}
