//
// 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 tipwidth=290;	// width of the picture in the tip
var tipheight=500;// Height of the picture in the tip


if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

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

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

function hascss(name){ return gettip(name)?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)||(navigator.userAgent.indexOf('MSIE 7')>0)))?true:false;
 kon=(navigator.userAgent.indexOf('konqueror')>0)?true:false;
 x=0;y=0;winW=800;winH=600;
 idiv=null;
 document.onmousemove = 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 untip(){
 if(idiv) idiv.visibility=ns4?"hide":"hidden";
 idiv=null;
}

function gettip(name){
  return document.getElementById(name).style;
  //(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(name)){
//		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");
		document.write('<div class="product-layer" id="'+name+'" name="'+name+'" style="position: absolute; visibility:hidden; z-index:20; top:0'+px+'; left:0'+px+';">'+text+'</div>'+"\n");
//	}
}

function tip(name) {
//	if(hascss(name)){
		if(idiv) untip();
		idiv=gettip(name);
		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
			}

			if(document.getElementById(name).firstChild)
			{
				tipwidth=document.getElementById(name).firstChild.width;
				tipheight=document.getElementById(name).firstChild.height;
			}
//			alert(winH);
//				  alert(":"+y+tipheight+":"+winH);
			showtip();
		}
//	}
}

function showtip(){

	//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;
	correct_y = correct_y - 20;
//	alert(y+":"+idiv.height+":"+winH);
	

	//set the position, but consider the available space and correct it if necessary
	idiv.left=(((x+tipwidth)<winW)?x+correct_x+0:x+correct_x-tipwidth)+px;
//	idiv.top=(((y+tipheight+correct_y)>winH)?y+correct_y-tipheight:y-correct_y)+px;
	idiv.top=(((y-tipheight+correct_y)<0)?y+correct_y:y+correct_y-tipheight)+px;
//	idiv.left=x+px;
//	idiv.top=y+px;
//	alert(idiv.left);
	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 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;
	}
	
	x=(winW-856)/2+220+13+200;
	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
