//
// Bubblehelp infoboxes, (C) 2002 Klaus Knopper <infobox@knopper.net>
// You can copy/modify and distribute this code under the conditions
// of the GNU GENERAL PUBLIC LICENSE Version 2.
//
var IWIDTH=250  // Tip box width
var ns4         // Are we using Netscape4?
var ie4         // Are we using Internet Explorer Version 4?
var ie5         // Are we using Internet Explorer Version 5 and up?
var kon         // Are we using KDE Konqueror?
var x,y,winW,winH  // Current help position and main window size
var idiv=null   // Pointer to map_layer container
var px="px"     // position suffix with "px" in some cases

// --------------------
var mousemoveing
var ID
var x1,y1
var StyleTextH, StyleTextW
// ---------------------


function nsfix(){setTimeout("window.onresize = rebrowse", 2000);}

function rebrowse(){window.location.reload();}

function hascss(){ return gettip('map_layer')?true:false }

function infoinit(){
 ns4=(document.layers)?true:false, ie4=(document.all)?true:false;
 ie5=((ie4)&&((navigator.userAgent.indexOf('MSIE 5')>0)||(navigator.userAgent.indexOf('MSIE 6')>0)))?true:false;
 kon=(navigator.userAgent.indexOf('konqueror')>0)?true:false;
 x=0;y=0;winW=800;winH=600;
 idiv=null;
 //document.onmousemove = pos;
 
 //var mousemoveing = mousemove;
 
 //if(ns4&&document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
 // Workaround for just another netscape bug: Fix browser confusion on resize
 // obviously conqueror has a similar problem :-(
 if(ns4||kon){ nsfix() }
 if(ns4) { px=""; }
}


function pos(event) {
 	if ((!document.all) && (event.layerX) && (event.layerY) && (event.layerX > 0) && (event.layerY > 0)) {
		x1 = event.layerX;
		y1 = event.layerY;
	}
}

function untip(id){
 if(idiv) idiv.visibility=ns4?"hide":"hidden";
 idiv=null;
 /*
 if (id != null) {
	 Img = document.getElementById('Layer-Img-mov-'+id).style.display;
	 Desc =	document.getElementById('Layer-Desc-mov-'+id).style.display;
	 
	 if(Desc == "block") {
		 document.getElementById('Layer-Img-mov-'+id).style.display = 'block';
		 document.getElementById('Layer-Desc-mov-'+id).style.display = 'none';
		 
		ImgClass = document.getElementById('Layer-Link-Img-'+id).className;
		DescClass = document.getElementById('Layer-Link-Desc-'+id).className;
			
		if(DescClass == "desc active") {
			
				DClass = document.getElementById('Layer-Link-Desc-'+id).className.replace(' active', '');
				document.getElementById('Layer-Link-Desc-'+id).className = DClass;
				
				
				ImgClass = ImgClass += ' active';
				document.getElementById('Layer-Link-Img-'+id).className = ImgClass;
				
		}
	 }
 }
 */
}

function gettip(name){
  return (document.layers&&document.layers[name])?document.layers[name]:(document.all&&document.all[name]&&document.all[name].style)?document.all[name].style:document[name]?document[name]:(document.getElementById(name)?document.getElementById(name).style:0);
}

// Prepare tip boxes, but don't show them yet
function maketip(name, text){
	if(hascss()){
		document.write('<div class="marker-layer" id="'+name+'" name="'+name+'" style="position: absolute; visibility:hidden; z-index:20; top:0'+px+'; left:0'+px+'; width: '+IWIDTH+'px;">'+text+'</div>'+"\n");
	}
}

function tip(name){	
	if(hascss()){
		id = null;
		if(idiv) untip(id);
		idiv=gettip(name);
		//hideTip();
		//idiv.style.width= 200+"px"
		
		if(idiv){
			winW=(window.innerWidth)? window.innerWidth+window.pageXOffset-16:document.body.offsetWidth-20;
			winH=(window.innerHeight)?window.innerHeight+window.pageYOffset  :document.body.offsetHeight;
			if(x<=0||y<=0){ // konqueror can't get mouse position
				x=(winW-IWIDTH)/2+(window.pageXOffset?window.pageXOffset:0); y=(winH-50)/2+(window.pageYOffset?window.pageYOffset:0); // middle of window
			}
			ID = name;
			showtip(name);
			
		}
		
	}
}

function showmap () {
  document.map.onclick = showtip(name);
}
window.onload = showmap;



function showtip(name){
	
	//window.onload = einblenden;
	//get the surrounding element of the tip, named "map_container"
	var container = null;
	if (document.layers&&document.layers['map_container']) {
		container = document.layers['map_container'];
	}
	else if (document.all&&document.all['map_container']) {
		container = document.all['map_container'];
	}
	else if (document['map_container']) {
		container = document['map_container'];
	} else if (document.getElementById('map_container')) {
		container = document.getElementById('map_container');
	}
		
	//calculate the real position of the surrounding element
	var correct_x=0;	
	var correct_y=0;	
	while (container) {
		correct_x = correct_x + container.offsetLeft;
		correct_y = correct_y + container.offsetTop;

		container = container.offsetParent;
	}

	//change the x/y-values to position the tip under the explorer tip
	correct_x = correct_x - 0; // - 0
	correct_y = correct_y - 154; // - 35

	
	//set the position, but consider the available space and correct it if necessary
	/*
	if(mousemoveing) {
		//console.log(mousemoveing);
		
		var e = mousemoveing;
		
			x1 = e.pageX?e.pageX:e.clientX?e.clientX:0;
			y1 = e.pageY?e.pageY:e.clientY?e.clientY:0;
	} 
	else */ if(window.event){
			
		x1 = window.event.clientX; 
		y1 = window.event.clientY;
		

		//console.log(x1);
		
		//x1 = window.event.layerX;
		//y1 = window.event.layerY;
		
		//console.log(x1);
		
		//x1 = window.event.pageX;
		//y1 = window.event.pageY;
		
		//console.log(x1);
	}
	/*else{
		x1=0; y1=0;

	}
	*/
	

	
	
	var Nr = ID.replace('layer', '');
	
	
	
	var LayerWidth = document.getElementById('Layer-'+Nr).offsetWidth;
	var ImgWidth = document.getElementById('Img-Map').offsetWidth;
	/*
	var Eltern = document.all.Img-Map.offsetParent;
	
	while (Eltern) {
  		abstand .= Eltern.offsetParent;
	}
	
	*/
	var ImgToPageLeft = document.getElementById('Img-Map').offsetParent.offsetLeft + document.getElementById('Img-Map').offsetParent.offsetParent.offsetLeft;
	
	
//	if(x1 > ImgWidth-LayerWidth+10) { x1=ImgWidth-LayerWidth+10; } else if(x1 < 20) { x1=20; } else { x1=x1; }


	x1 = parseInt((ImgWidth/2)-(LayerWidth/2)+ImgToPageLeft);

		

	//idiv.left=(((x)<winW)?x-correct_x:x-correct_x-260)+"px";
	idiv.left=(((x1)<winW)?x1-correct_x:x1-correct_x-260)+"px";
 	
	
	
	var LayerHeight = document.getElementById('Layer-'+Nr).offsetHeight;
	var ImgHeight = document.getElementById('Img-Map').offsetHeight;
	
	
//	if(y1 > ImgHeight-LayerHeight-5) { y1=ImgHeight-LayerHeight-10; } else if(y1 < 40) { y1=40; } else { y1=y1; }

	
	y1 = parseInt((ImgHeight/2)-(LayerHeight/2));

	//idiv.top=(((y)<winH)?y-correct_y:y-correct_y)+"px";
	idiv.top=(((y1)<winH)?y1-correct_y:y1-correct_y)+"px";
	
	idiv.visibility=ns4?"show":"visible";

	//window.status="idiv="+idiv+"X:"+(idiv.left?idiv.left:"NAN")+", Y:"+(idiv.top?idiv.top:"NAN")+", Mouse x:"+x+", y:"+y + " Container: " + posx + " : " + posy;
}
/*
function einblenden() {
		var Nr = ID.replace('layer', '');
		var lay = document.getElementById('Layer-'+Nr);
		
		setOpacity(lay, 0);
 		lay.style.visibility = "visible";
		fadeIn(lay, 0);
}
*/
function mousemove(e){
	
	
	if(e){
		x=e.pageX?e.pageX:e.clientX?e.clientX:0;
		y=e.pageY?e.pageY:e.clientY?e.clientY:0;
	}
	/*else if(event){
		x=event.clientX; y=event.clientY;
	}
	else{
		x=0; y=0;
	}
	

	if((ie4||ie5) && document.documentElement) { // Workaround for scroll offset of IE
		x+=document.documentElement.scrollLeft;
		y+=document.documentElement.scrollTop;
	}
	if(idiv) {
		showtip();
	}
	*/
}

// Initialize after loading the page
window.onload=infoinit;

// EOF infobox.js

/*
function showLayerInfo(div, id) {

	
	if(div == "img") {
		
			document.getElementById('Layer-Img-mov-'+id).style.display = 'block';
			//document.getElementById('Layer-Img-mov-'+id).style.height = StyleText;
			document.getElementById('Layer-Desc-mov-'+id).style.display = 'none';
			
			ImgClass = document.getElementById('Layer-Link-Img-'+id).className;
			DescClass = document.getElementById('Layer-Link-Desc-'+id).className.replace(' active' , '');
			
			if(ImgClass == "img") {
				document.getElementById('Layer-Link-Img-'+id).className += ' active';
			}
			document.getElementById('Layer-Link-Desc-'+id).className = DescClass;
	}
	else if(div == "desc") {
			document.getElementById('Layer-Img-mov-'+id).style.display = 'none';
			document.getElementById('Layer-Desc-mov-'+id).style.display = 'block';
			//document.getElementById('Layer-Desc-mov-'+id).style.height = StyleText;
			
			DescClass = document.getElementById('Layer-Link-Desc-'+id).className;
			ImgClass = document.getElementById('Layer-Link-Img-'+id).className.replace(' active', '');
			
			if(DescClass == "desc") {
				document.getElementById('Layer-Link-Desc-'+id).className += ' active';
			}
			document.getElementById('Layer-Link-Img-'+id).className = ImgClass;
	}
}

*/
/*
function LayerTextHeight(id) {
	var LH_D = document.getElementById('Layer-Desc-mov-'+Nr).offsetHeight;
	var LH_I = document.getElementById('Layer-Img-mov-'+Nr).offsetHeight;
	
	if(LH_D < LH_I) ? StyleTextH = LH_I : StyleTextH = LH_D;

}


function setOpacity(obj, opacity) {
	
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 1000);
    }
  }
}


function setOpacity(value) {
	testObj.style.opacity = value/10;
	testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
}
*/